Skip to content

Commit

Permalink
feat(form): optional limit the displayed error messages per field
Browse files Browse the repository at this point in the history
Added an optional setting errorLimit (default 0 = unlimited).
When set to an integer value, only that given number of possible rule errors per field are displayed
  • Loading branch information
lubber-de authored Apr 15, 2023
1 parent 1e3f606 commit 491b07a
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions src/definitions/behaviors/form.js
Original file line number Diff line number Diff line change
Expand Up @@ -1331,7 +1331,8 @@
fieldValid = true,
fieldErrors = [],
isDisabled = $field.filter(':not(:disabled)').length === 0,
validationMessage = $field[0].validationMessage
validationMessage = $field[0].validationMessage,
errorLimit
;
if (!field.identifier) {
module.debug('Using field name as identifier', identifier);
Expand All @@ -1354,8 +1355,9 @@
} else if (field.depends && module.is.empty($dependsField)) {
module.debug('Field depends on another value that is not present or empty. Skipping', $dependsField);
} else if (field.rules !== undefined) {
errorLimit = field.errorLimit || settings.errorLimit;
$.each(field.rules, function (index, rule) {
if (module.has.field(identifier)) {
if (module.has.field(identifier) && (!errorLimit || fieldErrors.length < errorLimit)) {
var invalidFields = module.validate.rule(field, rule, true) || [];
if (invalidFields.length > 0) {
module.debug('Field is invalid', identifier, rule.type);
Expand Down Expand Up @@ -1607,6 +1609,7 @@
preventLeaving: false,
errorFocus: true,
dateHandling: 'date', // 'date', 'input', 'formatter'
errorLimit: 0,

onValid: function () {},
onInvalid: function () {},
Expand Down

0 comments on commit 491b07a

Please sign in to comment.