I'm hitting a problem when using T. Hedersen's backbone.validation plugin (https://github.com/thedersen/backbone.validation) in conjunction with Derick Bailey's backbone.modelbinding plugin (https://github.com/derickbailey/backbone.modelbinding).
I've put together a jsFiddle example (http://jsfiddle.net/simax/bEqnZ/) to try and demonstrate the issue.
In the example if you remove the contents of the firstname or lastname the isValid(true) call still returns true, which is incorrect as both firstname and lastname are required fields. You'll also notice that the DisplayForm is not updated correctly. It appears that the models properties are not being "unset" correctly.
If however you remove the call to Backbone.Validation.this(bind) the model properties and DisplayForm are updated correctly.
Anyone know what the problem is?
Quick answer:
Change the validation line to:
Backbone.Validation.bind(this, {forceUpdate: true});
Background:
When the modelbinding tries to update the model, the validation fails and the model is not updated at all.
Setting the forceUpdate flag allows your model to be in an invalid state (and therefore can hold an empty string).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With