backbone.validation icon indicating copy to clipboard operation
backbone.validation copied to clipboard

Allow an option to configure validation only for the model's changed attributes

Open Soesah opened this issue 11 years ago • 12 comments

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

Soesah avatar Feb 05 '14 14:02 Soesah

When we are planning to incorporating this fix. I need this fix ASAP

shahjeet297 avatar Jan 27 '15 07:01 shahjeet297

I think the owner lost interest in Backbone Validation. It's not very likely to get merged any time soon.

Soesah avatar Jan 27 '15 07:01 Soesah

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); 
        }
    });

blikblum avatar Jan 27 '15 10:01 blikblum

Remember guys, to get what @blikblum recommended, please update the version of your Backbone.Validation.

chiefGui avatar Jan 27 '15 12:01 chiefGui

Hey blikbum,

This will not work as i have to validate only one attribute on tab out and all attributes on save.

shahjeet297 avatar Jan 28 '15 06:01 shahjeet297

Are you calling validate directly or through set?

blikblum avatar Jan 28 '15 12:01 blikblum

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

shahjeet297 avatar Jan 28 '15 16:01 shahjeet297

Sorry i was not clear, are you calling model.validate or model.set({validate:true})?

blikblum avatar Jan 28 '15 19:01 blikblum

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

shahjeet297 avatar Jan 29 '15 13:01 shahjeet297

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/

blikblum avatar Jan 29 '15 23:01 blikblum

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 .

shahjeet297 avatar Jan 30 '15 12:01 shahjeet297

validateAll is a variable of validate function that is set when validate os called with attrs argument undefined

blikblum avatar Jan 30 '15 15:01 blikblum