backbone.validation
backbone.validation copied to clipboard
backbone validate single attribute at a time
I have one model with 2 attributes as follows.
Backbone.Model.extend({
validation: {
username: [
{required: true, msg: 'Enter email/username.'},
],
password: [
{required: true,msg: 'Enter password.'},
{minLength:20,msg: 'Incorrect password length.'}]
},
});
I want validate single attribute at a time atleast in save function. means If username found invalid, then it return error and don't go for password validation, and this will come under some option/settings.
Thanks.
You can override Backbone.Model's _validate method to filter changed attributes. Inspired from: https://github.com/fantactuka/backbone-validator/blob/master/backbone-validator.js#L178