Skip to content

Commit

Permalink
When Validate When Typing is set on a form, ensure that the global …
Browse files Browse the repository at this point in the history
…form error message is removed after errors are fixed (when typing)
  • Loading branch information
engram-design committed Oct 15, 2020
1 parent 8c74d84 commit 9396242
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 4 deletions.
2 changes: 1 addition & 1 deletion src/web/assets/frontend/dist/js/formie.js

Large diffs are not rendered by default.

14 changes: 12 additions & 2 deletions src/web/assets/frontend/src/js/formie-form-theme.js
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,11 @@ export class FormieFormTheme {

this.validator = new Bouncer(this.formId, registerFormieValidation.detail.validatorSettings);

// After we clear any error, validate the fielset again. Mostly so we can remove global errors
this.form.addEventListener(document, 'bouncerRemoveError', (e) => {
this.validate(false);
});

// Override error messages defined in DOM - Bouncer only uses these as a last resort
// In future updates, we can probably remove this
this.form.addEventListener(document, 'bouncerShowError', (e) => {
Expand Down Expand Up @@ -209,7 +214,7 @@ export class FormieFormTheme {
return JSON.stringify(hash);
}

validate() {
validate(focus = true) {
if (!this.validationOnSubmit) {
return true;
}
Expand All @@ -223,10 +228,15 @@ export class FormieFormTheme {
var invalidFields = this.validator.validateAll($fieldset);

// If there are errors, focus on the first one
if (invalidFields.length > 0) {
if (invalidFields.length > 0 && focus) {
invalidFields[0].focus();
}

// Remove any global errors if none - just in case
if (invalidFields.length === 0) {
this.removeFormAlert();
}

return !invalidFields.length;
}

Expand Down
2 changes: 1 addition & 1 deletion src/web/assets/mix-manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,6 @@
"/frontend/dist/js/fields/table.js": "/frontend/dist/js/fields/table.js?id=8a85ee08ab92bf48543d",
"/frontend/dist/js/fields/tags.js": "/frontend/dist/js/fields/tags.js?id=7a0e7d5eef5c4a9517bf",
"/frontend/dist/js/fields/text-limit.js": "/frontend/dist/js/fields/text-limit.js?id=5b8e242f8c8abbdbae22",
"/frontend/dist/js/formie.js": "/frontend/dist/js/formie.js?id=c30a61266220938a25df",
"/frontend/dist/js/formie.js": "/frontend/dist/js/formie.js?id=e641b2aac89c217981a2",
"/repeater/dist/js/main.js": "/repeater/dist/js/main.js?id=abd0659b4ba104da3c63"
}

0 comments on commit 9396242

Please sign in to comment.