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

backbone validate single attribute at a time

Open sapkal-manish opened this issue 11 years ago • 1 comments

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.

sapkal-manish avatar Nov 28 '13 05:11 sapkal-manish

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

giiska avatar Feb 23 '14 14:02 giiska