@ -12,12 +12,18 @@ define(
var originalBeforeClose = this . prototype . onBeforeClose ;
var errorHandler = function ( response ) {
if ( this . model ) {
this . model . trigger ( 'validation:failed' , response ) ;
}
else {
this . trigger ( 'validation:failed' , response ) ;
}
} ;
var validatedSync = function ( method , model , options ) {
model . trigger ( 'validation:sync' ) ;
// this.$el.removeAllErrors();
arguments [ 2 ] . isValidatedCall = true ;
return model . _originalSync . apply ( this , arguments ) . fail ( errorHandler . bind ( this ) ) ;
} ;
@ -30,13 +36,7 @@ define(
}
} ;
this . prototype . onRender = function ( ) {
this . listenTo ( this . model , 'validation:sync' , function ( ) {
this . $el . removeAllErrors ( ) ;
} ) ;
this . listenTo ( this . model , 'validation:failed' , function ( response ) {
var validationFailed = function ( response ) {
if ( response . status === 400 ) {
var view = this ;
@ -45,8 +45,26 @@ define(
view . $el . processServerError ( error ) ;
} ) ;
}
} ;
this . prototype . onRender = function ( ) {
if ( this . model ) {
this . listenTo ( this . model , 'validation:sync' , function ( ) {
this . $el . removeAllErrors ( ) ;
} ) ;
this . listenTo ( this . model , 'validation:failed' , validationFailed ) ;
}
else {
this . listenTo ( this , 'validation:sync' , function ( ) {
this . $el . removeAllErrors ( ) ;
} ) ;
this . listenTo ( this , 'validation:failed' , validationFailed ) ;
}
Validation . bind ( this ) ;
this . bindToModelValidation = bindToModel . bind ( this ) ;