mirror of
				https://github.com/yiisoft/yii2.git
				synced 2025-11-01 03:26:36 +08:00 
			
		
		
		
	Added validation js callbacks
- `beforeValidateAll` - `afterValidateAll` fixes #4234, close #4559
This commit is contained in:
		 Alex-Code
					Alex-Code
				
			
				
					committed by
					
						 Carsten Brandt
						Carsten Brandt
					
				
			
			
				
	
			
			
			 Carsten Brandt
						Carsten Brandt
					
				
			
						parent
						
							e5b2fb2452
						
					
				
				
					commit
					594b57836d
				
			| @ -41,9 +41,15 @@ | ||||
|         // a callback that is called before validating each attribute. The signature of the callback should be: | ||||
|         // function ($form, attribute, messages) { ...return false to cancel the validation...} | ||||
|         beforeValidate: undefined, | ||||
|         // a callback that is called before validation starts (This callback is only called when the form is submitted). This signature of the callback should be: | ||||
|         // function($form, data) { ...return false to cancel the validation...} | ||||
|         beforeValidateAll: undefined, | ||||
|         // a callback that is called after an attribute is validated. The signature of the callback should be: | ||||
|         // function ($form, attribute, messages) | ||||
|         afterValidate: undefined, | ||||
|         // a callback that is called after all validation has run (This callback is only called when the form is submitted). The signature of the callback should be: | ||||
|         // function ($form, data, messages) | ||||
|         afterValidateAll: undefined, | ||||
|         // a pre-request callback function on AJAX-based validation. The signature of the callback should be: | ||||
|         // function ($form, jqXHR, textStatus) | ||||
|         ajaxBeforeSend: undefined, | ||||
| @ -152,6 +158,11 @@ | ||||
|                 clearTimeout(data.settings.timer); | ||||
|             } | ||||
|             data.submitting = true; | ||||
|              | ||||
|             if (data.settings.beforeValidateAll && !data.settings.beforeValidateAll($form, data)) { | ||||
|                 data.submitting = false; | ||||
|                 return false; | ||||
|             } | ||||
|             validate($form, function (messages) { | ||||
|                 var errors = []; | ||||
|                 $.each(data.attributes, function () { | ||||
| @ -159,6 +170,11 @@ | ||||
|                         errors.push(this.input); | ||||
|                     } | ||||
|                 }); | ||||
|                  | ||||
|                 if (data.settings.afterValidateAll) { | ||||
|                     data.settings.afterValidateAll($form, data, messages); | ||||
|                 } | ||||
|                  | ||||
|                 updateSummary($form, messages); | ||||
|                 if (errors.length) { | ||||
|                     var top = $form.find(errors.join(',')).first().offset().top; | ||||
|  | ||||
		Reference in New Issue
	
	Block a user