Skip to content

Commit

Permalink
fix(form): deprecated and rename empty to notEmpty rule
Browse files Browse the repository at this point in the history
  • Loading branch information
lubber-de committed Nov 30, 2023
1 parent 7259033 commit dea2ddb
Showing 1 changed file with 14 additions and 7 deletions.
21 changes: 14 additions & 7 deletions src/definitions/behaviors/form.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
}
}
});
Expand Down Expand Up @@ -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',
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit dea2ddb

Please sign in to comment.