Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions ui.frontend/src/view/FormFieldBase.js
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,7 @@ class FormFieldBase extends FormField {
#syncLabel() {
let labelElement = typeof this.getLabel === 'function' ? this.getLabel() : null;
if (labelElement) {
labelElement.setAttribute('id', `${this.getId()}__label`);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove this id

labelElement.setAttribute('for', this.getWidgetId());
}
}
Expand All @@ -176,6 +177,7 @@ class FormFieldBase extends FormField {
let errorElement = typeof this.getErrorDiv === 'function' ? this.getErrorDiv() : null;
if (errorElement) {
errorElement.setAttribute('id', `${this.getId()}__errormessage`);
errorElement.setAttribute('aria-describedby', `${this.getId()}__label`);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is already present in the input field. We can not use the aria-describedby attribute on the error container.

}
}

Expand Down Expand Up @@ -249,7 +251,7 @@ class FormFieldBase extends FormField {
this.#syncLabel()
this.#syncWidget()
this.#syncShortDesc()
this. #syncLongDesc()
this.#syncLongDesc()
this.#syncAriaDescribedBy()
this.#syncError()
this.#syncAriaLabel()
Expand Down Expand Up @@ -538,6 +540,8 @@ class FormFieldBase extends FormField {
// Check if the validationMessage is different from the current content
if (this.errorDiv.innerHTML !== state.validationMessage) {
this.errorDiv.innerHTML = state.validationMessage;
this.errorDiv.removeAttribute('tabindex');
this.errorDiv.removeAttribute('role');
if (state.validity.valid === false) {
// Find the first key whose value is true
const validationType = Object.keys(state.validity).find(key => key !== 'valid' && state.validity[key] === true);
Expand All @@ -550,7 +554,9 @@ class FormFieldBase extends FormField {
if (!state.validationMessage) {
this.errorDiv.innerHTML = LanguageUtils.getTranslatedString(this.formContainer.getModel().lang, "defaultError");
}
}
this.errorDiv.setAttribute('tabindex', 0);
this.errorDiv.setAttribute('role', 'complementary');
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is usually incorrect to use role="complementary" on an error container.
Use role="alert" or aria-live="assertive" for error messages, as this is the best practice(Optional)

}
this.#syncAriaDescribedBy();
}
}
Expand Down