mirror of
				https://github.com/yiisoft/yii2.git
				synced 2025-10-31 18:47:33 +08:00 
			
		
		
		
	Fixed #14901: fixed both implementation and test of trim() JavaScript validator
This commit is contained in:
		| @ -238,9 +238,7 @@ yii.validation = (function ($) { | ||||
|  | ||||
|         trim: function ($form, attribute, options, value) { | ||||
|             var $input = $form.find(attribute.input); | ||||
|             var isCheckAble = $input.find('[type=radio]').is('[type=radio]') || $input.find('[type=checkbox]').is('[type=checkbox]'); | ||||
|  | ||||
|             if (!isCheckAble) { | ||||
|             if ($input.is(':checkbox, :radio')) { | ||||
|                 return value; | ||||
|             } | ||||
|  | ||||
|  | ||||
| @ -1214,6 +1214,9 @@ describe('yii.validation', function () { | ||||
|         var $input = { | ||||
|             val: function () { | ||||
|                 return getInputVal(); | ||||
|             }, | ||||
|             is: function () { | ||||
|                 return false; | ||||
|             } | ||||
|         }; | ||||
|         var $form = { | ||||
| @ -1274,6 +1277,32 @@ describe('yii.validation', function () { | ||||
|         }); | ||||
|     }); | ||||
|  | ||||
|     describe('trim filter on checkbox', function () { | ||||
|         var attribute = {input: '#input-id'}; | ||||
|         var getInputVal; | ||||
|         var $checkbox = { | ||||
|             is: function (selector) { | ||||
|                 if (selector === ':checked') { | ||||
|                     return true; | ||||
|                 } | ||||
|  | ||||
|                 if (selector === ':checkbox, :radio') { | ||||
|                     return true; | ||||
|                 } | ||||
|             } | ||||
|         }; | ||||
|         var $form = { | ||||
|             find: function () { | ||||
|                 return $checkbox; | ||||
|             } | ||||
|         }; | ||||
|  | ||||
|  | ||||
|         it('should be left as is', function () { | ||||
|             assert.strictEqual(yii.validation.trim($form, attribute, {}, true), true); | ||||
|         }); | ||||
|     }); | ||||
|  | ||||
|     describe('captcha validator', function () { | ||||
|         // Converted using yii\captcha\CaptchaAction generateValidationHash() method | ||||
|         var hashes = {'Code': 379, 'code': 411}; | ||||
|  | ||||
		Reference in New Issue
	
	Block a user
	 Alexander Makarov
					Alexander Makarov