backbone.validation
backbone.validation copied to clipboard
Allow an option to configure validation only for the model's changed attributes
When validating a form on a field:blur currently triggers validation of all invalid properties in the model, and these show up as messages all over the form.
Setting useChangedAttr
forces the validation to be triggered only for the changed attributes. This request is based on work done in https://github.com/jeroensen/backbone.validation
When we are planning to incorporating this fix. I need this fix ASAP
I think the owner lost interest in Backbone Validation. It's not very likely to get merged any time soon.
Recently was added the ability to configure what attributes to be validated. Take a look to see if this will work:
Backbone.Validation.bind(this, {
attributes: function(view) {
return _.keys(view.model.changed);
}
});
Remember guys, to get what @blikblum recommended, please update the version of your Backbone.Validation.
Hey blikbum,
This will not work as i have to validate only one attribute on tab out and all attributes on save.
Are you calling validate
directly or through set
?
Yes
On Wed, Jan 28, 2015 at 6:00 PM, Luiz Américo [email protected] wrote:
Are you calling validate directly or through set?
— Reply to this email directly or view it on GitHub https://github.com/thedersen/backbone.validation/pull/202#issuecomment-71827602 .
jitendra shah 09811736177 09414233019
Sorry i was not clear, are you calling model.validate or model.set({validate:true})?
model.set({validate:true})
On Thu, Jan 29, 2015 at 12:33 AM, Luiz Américo [email protected] wrote:
Sorry i was not clear, are you calling model.validate or model.set({validate:true})?
— Reply to this email directly or view it on GitHub https://github.com/thedersen/backbone.validation/pull/202#issuecomment-71894267 .
jitendra shah 09811736177 09414233019
I could not reproduce the problem here.
Although all attributes are validated, only the changed ones fire the invalid callback
In validate
there's a check to prevent invalid callback being fired if the attr is not changed:
if(invalid && (changed || validateAll)){
opt.invalid(view, attr, result.invalidAttrs[attr], opt.selector);
}
You can check here that only changed attr get the error message: http://jsfiddle.net/thedersen/c3kK2/
ValidateAll flag is not present in the version 0.1.0. On Jan 30, 2015 5:23 AM, "Luiz Américo" [email protected] wrote:
I could not reproduce the problem here. Although the all attributes are validated only the changed ones fire invalid callback In validate there's a check to prevent invalid callback being fired if the attr is not changed:
if(invalid && (changed || validateAll)){ opt.invalid(view, attr, result.invalidAttrs[attr], opt.selector); }
You can check here that only changed attr get the error message: http://jsfiddle.net/thedersen/c3kK2/
— Reply to this email directly or view it on GitHub https://github.com/thedersen/backbone.validation/pull/202#issuecomment-72128728 .
validateAll
is a variable of validate
function that is set when validate os called with attrs argument undefined