Skip to content

Commit

Permalink
fix(formvalidation): improve disabled fields check
Browse files Browse the repository at this point in the history
Whenever a (required) form field gets disabled by adding the disabled class to the field label (rather than the input itself) after the whole form was initialized, the validation failed.
native required but disabled input fields are ignored by default, so FUI should also support that
  • Loading branch information
lubber-de committed Mar 23, 2024
1 parent 4e43130 commit 6e78472
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions src/definitions/behaviors/form.js
Original file line number Diff line number Diff line change
Expand Up @@ -1350,12 +1350,13 @@
var
identifier = field.identifier || fieldName,
$field = module.get.field(identifier),
$fieldGroup = $field.closest($group),
$dependsField = field.depends
? module.get.field(field.depends)
: false,
fieldValid = true,
fieldErrors = [],
isDisabled = $field.filter(':not(:disabled)').length === 0,
isDisabled = $field.filter(':not(:disabled)').length === 0 || $fieldGroup.hasClass(className.disabled) || $fieldGroup.parent().hasClass(className.disabled),
validationMessage = $field[0].validationMessage,
noNativeValidation = field.noNativeValidation || settings.noNativeValidation || $field.filter('[formnovalidate],[novalidate]').length > 0 || $module.filter('[novalidate]').length > 0,
errorLimit
Expand All @@ -1364,15 +1365,15 @@
module.debug('Using field name as identifier', identifier);
field.identifier = identifier;
}
if (validationMessage && !noNativeValidation) {
if (validationMessage && !noNativeValidation && !isDisabled) {
module.debug('Field is natively invalid', identifier);
fieldErrors.push(validationMessage);
fieldValid = false;
if (showErrors) {
$field.closest($group).addClass(className.error);
$fieldGroup.addClass(className.error);
}
} else if (showErrors) {
$field.closest($group).removeClass(className.error);
$fieldGroup.removeClass(className.error);
}
if (isDisabled) {
module.debug('Field is disabled. Skipping', identifier);
Expand Down

0 comments on commit 6e78472

Please sign in to comment.