aw-front-helpers 2.5.5 → 2.5.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/classes/formControl.js +9 -6
- package/package.json +1 -1
package/classes/formControl.js
CHANGED
|
@@ -103,23 +103,26 @@ export default class FormControl {
|
|
|
103
103
|
if (parent === null) return;
|
|
104
104
|
let error = parent.querySelector(`.${this._options.classErrorElement}`);
|
|
105
105
|
parent.classList.add(this._options.classIsError);
|
|
106
|
+
const id = `error-${[...Array(6)].map(() => Math.floor(Math.random() * 16).toString(16)).join('')}`;
|
|
106
107
|
if (!error) {
|
|
107
108
|
error = Object.assign(
|
|
108
109
|
document.createElement('p'), {
|
|
109
|
-
|
|
110
|
-
|
|
110
|
+
id,
|
|
111
|
+
className: this._options.classErrorElement,
|
|
112
|
+
innerHTML: message
|
|
111
113
|
});
|
|
112
|
-
|
|
114
|
+
element.setAttribute('aria-describedby', id);
|
|
113
115
|
parent.appendChild(error);
|
|
114
116
|
} else {
|
|
115
117
|
if (error.tagName === 'P') {
|
|
116
118
|
if (message === error.innerHTML) return;
|
|
117
119
|
const newError = Object.assign(
|
|
118
120
|
document.createElement('ul'), {
|
|
119
|
-
|
|
120
|
-
|
|
121
|
+
id,
|
|
122
|
+
className: this._options.classErrorElement,
|
|
123
|
+
innerHTML: `<li>${error.innerHTML}</li>`
|
|
121
124
|
});
|
|
122
|
-
|
|
125
|
+
element.setAttribute('aria-describedby', id);
|
|
123
126
|
parent.appendChild(newError);
|
|
124
127
|
error.parentNode.removeChild(error);
|
|
125
128
|
error = newError;
|