Fixed #14901: fixed both implementation and test of trim() JavaScript validator

This commit is contained in:
Alexander Makarov
2018-09-08 02:12:34 +03:00
parent cd442339df
commit 8b3da74fc0
2 changed files with 30 additions and 3 deletions

View File

@ -238,9 +238,7 @@ yii.validation = (function ($) {
trim: function ($form, attribute, options, value) { trim: function ($form, attribute, options, value) {
var $input = $form.find(attribute.input); var $input = $form.find(attribute.input);
var isCheckAble = $input.find('[type=radio]').is('[type=radio]') || $input.find('[type=checkbox]').is('[type=checkbox]'); if ($input.is(':checkbox, :radio')) {
if (!isCheckAble) {
return value; return value;
} }

View File

@ -1214,6 +1214,9 @@ describe('yii.validation', function () {
var $input = { var $input = {
val: function () { val: function () {
return getInputVal(); return getInputVal();
},
is: function () {
return false;
} }
}; };
var $form = { 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 () { describe('captcha validator', function () {
// Converted using yii\captcha\CaptchaAction generateValidationHash() method // Converted using yii\captcha\CaptchaAction generateValidationHash() method
var hashes = {'Code': 379, 'code': 411}; var hashes = {'Code': 379, 'code': 411};