Skip to content

Commit 2d271dc

Browse files
author
Luiz Américo
committed
Allow 'isValid' to check specific attributes even when no View is associated with the model. thedersen#302
1 parent 710b1af commit 2d271dc

File tree

1 file changed

+9
-6
lines changed

1 file changed

+9
-6
lines changed

src/backbone-validation.js

+9-6
Original file line numberDiff line numberDiff line change
@@ -244,14 +244,17 @@ Backbone.Validation = (function(_){
244244
}
245245
if (attrs) {
246246
flattened = flatten(this.attributes);
247-
//Loop through all associated views
248-
_.each(this.associatedViews, _.bind(function(view) {
249-
_.each(attrs, _.bind(function (attr) {
250-
error = validateAttr(this, attr, flattened[attr], _.extend({}, this.attributes));
251-
if (error) {
252-
options.invalid(view, attr, error, options.selector, this);
247+
//Loop through all attributes and mark attributes invalid if appropriate
248+
_.each(attrs, _.bind(function (attr) {
249+
error = validateAttr(this, attr, flattened[attr], _.extend({}, this.attributes));
250+
if (error) {
253251
invalidAttrs = invalidAttrs || {};
254252
invalidAttrs[attr] = error;
253+
}
254+
//trigger valid/invalid events for each associated view
255+
_.each(this.associatedViews, _.bind(function(view) {
256+
if (error) {
257+
options.invalid(view, attr, error, options.selector, this);
255258
} else {
256259
options.valid(view, attr, options.selector, this);
257260
}

0 commit comments

Comments
 (0)