Required Fields on Multiple Models

  • 2
  • Problem
  • Updated 5 years ago
  • Acknowledged
I have a page which can create a new Account, Contact and Task (Log a Call) all within the same screen.

The Account and Contact fields both have required fields.  I have the main Save button wired to all three models.

I would like to give the user the option of creating one or all three new records. Is it possible to only apply the Required fields requirement if the model is not blank? Currently if a user fills fields for company, decides that is all that is currently important, and clicks save, the user gets an error that a required field is not complete (from the Contact last name, in this example).

Will separating the save button to the three models individually get rid of this behavior? Thats a lot of save buttons!

Thanks,

 Jacob
Photo of Jacob Flatter

Jacob Flatter

  • 338 Points 250 badge 2x thumb
  • unsure

Posted 5 years ago

  • 2
Photo of Rob Hatch

Rob Hatch, Official Rep

  • 44,006 Points 20k badge 2x thumb
If separate save buttons are only wired up to a single model, the validation on other models will not be fired.  This would be a way to get around the situation you are having.   (I'd put the save / cancel buttons on the individual field editors so they were better connected to the object being addressed. 

I think you could solve the primary problem with a custom save button.  The Javascript in that button would need to listen to changes on the models and only attempt to save if changes were identified.  
Photo of Peter Bender

Peter Bender, Champion

  • 6,246 Points 5k badge 2x thumb
Rob, how would the javascript know which models have been changed?
Photo of Jacob Flatter

Jacob Flatter

  • 1,512 Points 1k badge 2x thumb
Changes are shown in the following var model = skuid.model.getModel('Account') ;  model.changes ; but this includes the conditions which tie it to the parent object.
Photo of Jacob Flatter

Jacob Flatter

  • 1,512 Points 1k badge 2x thumb
Same question here. I see that I could save only certain models, but I am unsure of how to notice the change.  It is also not just a change, but that there currently exists a value in one of the model's fields.  If a user enters a value, changes his mind, and clicks save, I don't want to attempt saving an empty model.

Thats the real trick, noticing an empty model on the button click.
Photo of Jacob Flatter

Jacob Flatter

  • 1,512 Points 1k badge 2x thumb