Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[TASK] Add the aria-invalid attribute to mark fields as invalid
Browse files Browse the repository at this point in the history
Related: #962
deoostfrees authored and mschwemer committed Oct 23, 2024

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
1 parent 244150b commit 65b804b
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions Resources/Private/Build/JavaScript/FormValidation.js
Original file line number Diff line number Diff line change
@@ -386,6 +386,7 @@ class Form {
#setError(type, field) {
this.#removeError(type, field);
this.#addErrorClass(field);
this.#addErrorAttribute(field);
let message = field.getAttribute('data-powermail-' + type + '-message') ||
field.getAttribute('data-powermail-error-message') || 'Validation error';
this.#addErrorMessage(message, field);
@@ -397,6 +398,7 @@ class Form {
*/
#removeError(type, field) {
this.#removeErrorClass(field);
this.#removeErrorAttribute(field);
this.#removeErrorMessages(field);
};

@@ -422,6 +424,28 @@ class Form {
}
};

#addErrorAttribute(field) {
if (field.getAttribute(this.#errorContainerClass)) {
let elements = document.querySelectorAll(field.getAttribute(this.#errorContainerClass));
for (let i = 0; i < elements.length; i++) {
elements[i].setAttribute('aria-invalid', 'true');
}
} else {
field.setAttribute('aria-invalid', 'true');
}
};

#removeErrorAttribute(field) {
if (field.getAttribute(this.#errorContainerClass)) {
let elements = document.querySelectorAll(field.getAttribute(this.#errorContainerClass));
for (let i = 0; i < elements.length; i++) {
elements[i].removeAttribute('aria-invalid');
}
} else {
field.removeAttribute('aria-invalid');
}
};

#addErrorMessage(message, field) {
let errorContainer = document.createElement('ul');
errorContainer.classList.add(this.#errorMessageContainerClass);

0 comments on commit 65b804b

Please sign in to comment.