From dea2ddbfb2ee6d22034c20745424285540b72ff7 Mon Sep 17 00:00:00 2001 From: lubber-de Date: Thu, 30 Nov 2023 22:30:34 +0100 Subject: [PATCH] fix(form): deprecated and rename empty to notEmpty rule --- src/definitions/behaviors/form.js | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/src/definitions/behaviors/form.js b/src/definitions/behaviors/form.js index 67893cc717..0f8e279381 100644 --- a/src/definitions/behaviors/form.js +++ b/src/definitions/behaviors/form.js @@ -1237,20 +1237,20 @@ isRequired = $el.prop('required') || $elGroup.hasClass(className.required) || $elGroup.parent().hasClass(className.required), isDisabled = $el.is(':disabled') || $elGroup.hasClass(className.disabled) || $elGroup.parent().hasClass(className.disabled), validation = module.get.validation($el), - hasEmptyRule = validation + hasNotEmptyRule = validation ? $.grep(validation.rules, function (rule) { - return rule.type === 'empty'; - }) !== 0 + return ['notEmpty', 'checked', 'empty'].indexOf(rule.type) >= 0; + }).length > 0 : false, identifier = module.get.identifier(validation, $el) ; - if (isRequired && !isDisabled && !hasEmptyRule && identifier !== undefined) { + if (isRequired && !isDisabled && !hasNotEmptyRule && identifier !== undefined) { if (isCheckbox) { module.verbose("Adding 'checked' rule on field", identifier); module.add.rule(identifier, 'checked'); } else { - module.verbose("Adding 'empty' rule on field", identifier); - module.add.rule(identifier, 'empty'); + module.verbose("Adding 'notEmpty' rule on field", identifier); + module.add.rule(identifier, 'notEmpty'); } } }); @@ -1669,6 +1669,7 @@ maxValue: '{name} must have a maximum value of {ruleValue}', minValue: '{name} must have a minimum value of {ruleValue}', empty: '{name} must have a value', + notEmpty: '{name} must have a value', checked: '{name} must be checked', email: '{name} must be a valid e-mail', url: '{name} must be a valid url', @@ -1801,10 +1802,16 @@ rules: { // is not empty or blank string - empty: function (value) { + notEmpty: function (value) { return !(value === undefined || value === '' || (Array.isArray(value) && value.length === 0)); }, + empty: function (value, ancillary, module) { + module.debug('Rule "empty" is deprecated and will be removed in a future version. Use the "notEmpty" rule instead.'); + + return $.fn.form.settings.rules.notEmpty(value); + }, + // checkbox checked checked: function () { return $(this).filter(':checked').length > 0;