Skip to content

Commit

Permalink
fix(form): dynamic validation should't check deleted fields
Browse files Browse the repository at this point in the history
When a field was dynamically removed after form initialization, validation still tried to check the removed field, resulting in an error.

This PR adds a check for still existing fields, and remove validation rules for those which doesn't exist anymore.
  • Loading branch information
prudho authored Dec 28, 2022
1 parent 1124496 commit c245e0f
Showing 1 changed file with 18 additions and 1 deletion.
19 changes: 18 additions & 1 deletion src/definitions/behaviors/form.js
Original file line number Diff line number Diff line change
Expand Up @@ -934,7 +934,11 @@
}
if (rule === undefined) {
module.debug('Removed all rules');
validation[field].rules = [];
if (module.has.field(field)) {
validation[field].rules = [];
} else {
delete validation[field];
}

return;
}
Expand Down Expand Up @@ -1124,6 +1128,14 @@
},
autoCheck: function () {
module.debug('Enabling auto check on required fields');
if (validation) {
$.each(validation, function (fieldName) {
if (!module.has.field(fieldName)) {
module.verbose('Field not found, removing from validation', fieldName);
module.remove.field(fieldName);
}
});
}
$field.each(function (_index, el) {
var
$el = $(el),
Expand Down Expand Up @@ -1229,6 +1241,11 @@
fieldName = field;
field = validation[field];
}
if (!field) {
module.debug('Unable to find field validation. Skipping', fieldName);

return true;
}
var
identifier = field.identifier || fieldName,
$field = module.get.field(identifier),
Expand Down

0 comments on commit c245e0f

Please sign in to comment.