Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

Soesah
Copy link

@Soesah Soesah commented Feb 5, 2014

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

@shahjeet297
Copy link

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

@Soesah
Copy link
Author

Soesah commented Jan 27, 2015

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

@blikblum
Copy link
Contributor

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

@chiefGui
Copy link
Collaborator

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

@shahjeet297
Copy link

Hey blikbum,

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

@blikblum
Copy link
Contributor

Are you calling validate directly or through set?

@shahjeet297
Copy link

Yes

On Wed, Jan 28, 2015 at 6:00 PM, Luiz Américo notifications@github.com
wrote:

Are you calling validate directly or through set?


Reply to this email directly or view it on GitHub
#202 (comment)
.

jitendra shah
09811736177
09414233019

@blikblum
Copy link
Contributor

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

@shahjeet297
Copy link

model.set({validate:true})

On Thu, Jan 29, 2015 at 12:33 AM, Luiz Américo notifications@github.com
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
#202 (comment)
.

jitendra shah
09811736177
09414233019

@blikblum
Copy link
Contributor

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/

@shahjeet297
Copy link

ValidateAll flag is not present in the version 0.1.0.
On Jan 30, 2015 5:23 AM, "Luiz Américo" notifications@github.com 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
#202 (comment)
.

@blikblum
Copy link
Contributor

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants