Skip to content

Commit 6e78472

Browse files
authored
fix(formvalidation): improve disabled fields check
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
1 parent 4e43130 commit 6e78472

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

src/definitions/behaviors/form.js

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1350,12 +1350,13 @@
13501350
var
13511351
identifier = field.identifier || fieldName,
13521352
$field = module.get.field(identifier),
1353+
$fieldGroup = $field.closest($group),
13531354
$dependsField = field.depends
13541355
? module.get.field(field.depends)
13551356
: false,
13561357
fieldValid = true,
13571358
fieldErrors = [],
1358-
isDisabled = $field.filter(':not(:disabled)').length === 0,
1359+
isDisabled = $field.filter(':not(:disabled)').length === 0 || $fieldGroup.hasClass(className.disabled) || $fieldGroup.parent().hasClass(className.disabled),
13591360
validationMessage = $field[0].validationMessage,
13601361
noNativeValidation = field.noNativeValidation || settings.noNativeValidation || $field.filter('[formnovalidate],[novalidate]').length > 0 || $module.filter('[novalidate]').length > 0,
13611362
errorLimit
@@ -1364,15 +1365,15 @@
13641365
module.debug('Using field name as identifier', identifier);
13651366
field.identifier = identifier;
13661367
}
1367-
if (validationMessage && !noNativeValidation) {
1368+
if (validationMessage && !noNativeValidation && !isDisabled) {
13681369
module.debug('Field is natively invalid', identifier);
13691370
fieldErrors.push(validationMessage);
13701371
fieldValid = false;
13711372
if (showErrors) {
1372-
$field.closest($group).addClass(className.error);
1373+
$fieldGroup.addClass(className.error);
13731374
}
13741375
} else if (showErrors) {
1375-
$field.closest($group).removeClass(className.error);
1376+
$fieldGroup.removeClass(className.error);
13761377
}
13771378
if (isDisabled) {
13781379
module.debug('Field is disabled. Skipping', identifier);

0 commit comments

Comments
 (0)