You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
It would be useful to validate only the fields that exist in the form for instance, if I want to validate on one form against the user model with the properties : username and email but I also have validation rules on the user model the correspond to phone number and address for instance, the model is never vaild when it's just validated against the username and email as it also checks for phone number and address.
I don't want to create a unique model for each form however, I just want to validate against the single model but only the specified fields.
You can do model.isValid(['email', 'username']); but this only returns true or false whereas model.validate() or model.set(props, {validate : true}); will validate the entire model including properties that don't exist in the form.
I propose that this module only validates against a model if the names are in the form or that isValid() also returns the corresponding error message.
The text was updated successfully, but these errors were encountered:
I have a solution that works pretty well and only modifies the existing code a small amount.
The user can call the validate method on the model and pass an option changedAttrs : true.
For example : this.set(user, {validate : true, changedAttrs : true});
Then in the backbone-validation.js file in the validate mixin on line 223, the result variable (line 233) can be set by checking for the changedAttrs option, if it exists, then it only validates the changed attributes or the ones sent in the form.
For example : result = validateModel(model, opt.changedAttrs ? changedAttrs : allAttrs);
That way I can choose to validate just the form components without having to make a model for each form and also if I want, I can validate the entire model if I ever need to.
It would be useful to validate only the fields that exist in the form for instance, if I want to validate on one form against the user model with the properties : username and email but I also have validation rules on the user model the correspond to phone number and address for instance, the model is never vaild when it's just validated against the username and email as it also checks for phone number and address.
I don't want to create a unique model for each form however, I just want to validate against the single model but only the specified fields.
You can do model.isValid(['email', 'username']); but this only returns true or false whereas model.validate() or model.set(props, {validate : true}); will validate the entire model including properties that don't exist in the form.
I propose that this module only validates against a model if the names are in the form or that isValid() also returns the corresponding error message.
The text was updated successfully, but these errors were encountered: