Using Backbone.ModelBinding with Backbone.Validation

I am facing an issue when using the T. Hedersen backbone.validation plugin ( https://github.com/thedersen/backbone.validation ) in conjunction with the Derick Bailey 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 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?

+3


source to share


1 answer


Quick answer :

Change the validation line to:

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

      



Background

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).

+5


source







All Articles