Skip to content

Commit c245e0f

Browse files
authored
fix(form): dynamic validation should't check deleted fields
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.
1 parent 1124496 commit c245e0f

File tree

1 file changed

+18
-1
lines changed

1 file changed

+18
-1
lines changed

src/definitions/behaviors/form.js

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -934,7 +934,11 @@
934934
}
935935
if (rule === undefined) {
936936
module.debug('Removed all rules');
937-
validation[field].rules = [];
937+
if (module.has.field(field)) {
938+
validation[field].rules = [];
939+
} else {
940+
delete validation[field];
941+
}
938942

939943
return;
940944
}
@@ -1124,6 +1128,14 @@
11241128
},
11251129
autoCheck: function () {
11261130
module.debug('Enabling auto check on required fields');
1131+
if (validation) {
1132+
$.each(validation, function (fieldName) {
1133+
if (!module.has.field(fieldName)) {
1134+
module.verbose('Field not found, removing from validation', fieldName);
1135+
module.remove.field(fieldName);
1136+
}
1137+
});
1138+
}
11271139
$field.each(function (_index, el) {
11281140
var
11291141
$el = $(el),
@@ -1229,6 +1241,11 @@
12291241
fieldName = field;
12301242
field = validation[field];
12311243
}
1244+
if (!field) {
1245+
module.debug('Unable to find field validation. Skipping', fieldName);
1246+
1247+
return true;
1248+
}
12321249
var
12331250
identifier = field.identifier || fieldName,
12341251
$field = module.get.field(identifier),

0 commit comments

Comments
 (0)