@@ -244,14 +244,17 @@ Backbone.Validation = (function(_){
244
244
}
245
245
if ( attrs ) {
246
246
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 ) {
253
251
invalidAttrs = invalidAttrs || { } ;
254
252
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 ) ;
255
258
} else {
256
259
options . valid ( view , attr , options . selector , this ) ;
257
260
}
0 commit comments