1
votes

Supposed I have a model containing 2 pre-populated fields. I would like to display these fields in the DOM for the user to modify if necessary. If I bind the DOM to the model using: {{input value=field1}} and {{input value=field2}}, then every time the user types in a character in one of these fields, Ember updates the bound model immediately. This is not the behavior I want. I prefer to show a button; when pressed, I want to validate data in the two fields in relation to each other, and if valid, update the model.

I considered creating mirrored fields in the controller and binding these to the DOM. Then create an action associated with the button to do the validation, and if data is found to be valid, copy data from the controller fields to the respective model fields. This technique may work, but seems like a very round-about way of doing something conceptually simple.

Do one of you Ember gurus out there have an opinion on how best to do this? I'm looking for best practices; please help.

1

1 Answers

1
votes

I am not a guru nor am I familiar with client side validation in EmberData since our app uses server side validation.

  1. Are you sure you can't allow your model to be updated immediately (i.e. bound to the template fields)?

    If you did bind the model, then you could validate upon submission. If validation fails, you can just rollback the changes. If it passes, you can save the record. This is probably what I would do.

  2. However, you clearly state that you do not want your model updated immediately, which means you don't want to bind your model.

    Also, you have to do some processing that depends on multiple fields to validate, so it really sounds like binding to the controller and having a validation action is a good solution and that's what I would do if I wasn't binding to the model.