Using Backbone.ModelBinding with Backbone.Validation

I am facing an issue when using the T. Hedersen backbone.validation plugin ( ) in conjunction with the Derick Bailey backbone.modelbinding plugin ( modelbinding ).

I've put together a jsFiddle example ( ) to try and demonstrate the problem.

In the example, when you remove the contents of the first name or last name, the call to isValid (true) still returns true, which is incorrect, since both first and last name are required. You will also notice that the DisplayForm is not updating correctly. It looks like the properties of the models are not "configured correctly".

If you remove the call to Backbone.Validation.this (binding), the model and DisplayForm properties are updated correctly.

Does anyone know what the problem is?


source to share

1 answer

Quick answer :

Change the validation line to:

Backbone.Validation.bind(this, {forceUpdate: true});



When model binding tries to update the model, 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 may contain an empty string).



All Articles