-
-
Notifications
You must be signed in to change notification settings - Fork 5.4k
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
Is passing all attributes instead of the delta to validate really a good option? #914
Comments
If you'd like to check the current state of the model -- it's available in
... in any case, |
The thing is, that using it with form validation works pretty good (using Backbone.Modelbinding and Backbone.Validation plugins), but this change pretty much makes it impossible. I would definitely not like having to specify validation twice. |
Btw, since validate effectively prevents invalid values being set on the model, I don't see the need to validate all attributes every time. Attributes not being changed will always be valid. |
I agree that this is a bit problematic. I understand that the validate method is intended to validate the model, not a form, but there are reasons other than form validation to validate model attributes one at a time. For example, if I have a number of set operations in a row on the same mode, if the first set is invalid I don't want to continue with the following sets; there'd be no point. Anyway, the workaround is to pass {silent: true} to each of the sets and let the save operation call the validate function. |
Actually yes -- that's exactly how the |
Yeah, I've spent a while trying to figure this one out. @thedersen - i'm using your validation library :D _validate: function(attrs, options) {
if (options.silent || !this.validate) return true;
attrs = _.extend({}, this.attributes, attrs);
var error = this.validate(attrs, options);
... The attrs passed into the _validate function represents the attrs that were changed. I just wrote an override for the Backone._validate function, which essentially justs comments out the attribute merge, and that does the trick, but I'm worried there will be side effects... Passing in the {silent:true} will just cause the validation to not occur. We need the validation to occur! The goal is to perform some client side validation, so we don't have to make a round trip to the server. Ultimately we just need an easy way of figuring out which attributes are invalid, and the commit that @thedersen pointed out no longer gives us the ability to do so. |
@jashkenas What's your new take on this after 0.9.9 (see your comment above regarding I've only managed to skim through the delta for 0.9.9 so far, but it looks like there's still validation of all attributes for every From the change log |
@tgriesser Awesome, I was surprised when I didn't find a more recent issue in the topic. |
According to this commit the
validate
method now receives the computed new state of the attrs, not just the delta.What this means is that there are no longer any way of knowing which attributes that has changed while performing validation, if I haven't missed something that is.
This is a problem when validating form input while the user is filling out the form. You usually do not want to validate form elements that has not been changed yet, but notify the user about errors on elements that has changed.
Maybe @jashkenas can comment on this?
The text was updated successfully, but these errors were encountered: