From dea2ddbfb2ee6d22034c20745424285540b72ff7 Mon Sep 17 00:00:00 2001 From: lubber-de Date: Thu, 30 Nov 2023 22:30:34 +0100 Subject: [PATCH 1/3] 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; From 2308b341ade3ca4c6a1e8b9465ab9727540e0fad Mon Sep 17 00:00:00 2001 From: lubber-de Date: Sat, 2 Dec 2023 00:46:32 +0100 Subject: [PATCH 2/3] feat(form): deprecated and rename empty to notEmpty rule --- src/definitions/behaviors/form.js | 26 ++++++++++++++++++++------ 1 file changed, 20 insertions(+), 6 deletions(-) diff --git a/src/definitions/behaviors/form.js b/src/definitions/behaviors/form.js index 0f8e279381..bbf3233339 100644 --- a/src/definitions/behaviors/form.js +++ b/src/definitions/behaviors/form.js @@ -538,6 +538,14 @@ fullFields[name].rules.push({ type: rule }); }); } + + $.each(fullFields[name].rules, function (index, rule) { + var ruleName = module.get.ruleName(rule); + if (ruleName === 'empty') { + module.warn('*** DEPRECATED *** : Rule "empty" for field "' + name +'" will be removed in a future version. -> Use "notEmpty" rule instead.'); + } + }); + }); return fullFields; @@ -591,10 +599,10 @@ }, settings: function () { if ($.isPlainObject(parameters)) { - if (parameters.fields) { - parameters.fields = module.get.fieldsFromShorthand(parameters.fields); - } settings = $.extend(true, {}, $.fn.form.settings, parameters); + if (settings.fields) { + settings.fields = module.get.fieldsFromShorthand(settings.fields); + } validation = $.extend(true, {}, $.fn.form.settings.defaults, settings.fields); module.verbose('Extending settings', validation, settings); } else { @@ -1491,6 +1499,12 @@ module.error.apply(console, arguments); } }, + warn: function () { + if (!settings.silent) { + module.warn = Function.prototype.bind.call(console.warn, console, settings.name + ':'); + module.warn.apply(console, arguments); + } + }, performance: { log: function (message) { var @@ -1605,6 +1619,7 @@ name: 'Form', namespace: 'form', + silent: false, debug: false, verbose: false, performance: true, @@ -1806,9 +1821,8 @@ 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.'); - + /* Deprecated */ + empty: function (value) { return $.fn.form.settings.rules.notEmpty(value); }, From cc71ceb2d91ca3cb8b647d4482c027dacb9146d0 Mon Sep 17 00:00:00 2001 From: lubber-de Date: Sat, 2 Dec 2023 00:48:56 +0100 Subject: [PATCH 3/3] feat(form): deprecated and rename empty to notEmpty rule --- src/definitions/behaviors/form.js | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/definitions/behaviors/form.js b/src/definitions/behaviors/form.js index bbf3233339..43a4352fea 100644 --- a/src/definitions/behaviors/form.js +++ b/src/definitions/behaviors/form.js @@ -542,10 +542,9 @@ $.each(fullFields[name].rules, function (index, rule) { var ruleName = module.get.ruleName(rule); if (ruleName === 'empty') { - module.warn('*** DEPRECATED *** : Rule "empty" for field "' + name +'" will be removed in a future version. -> Use "notEmpty" rule instead.'); + module.warn('*** DEPRECATED *** : Rule "empty" for field "' + name + '" will be removed in a future version. -> Use "notEmpty" rule instead.'); } }); - }); return fullFields;