aw-front-helpers 2.5.5 → 2.5.7
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 +13 -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;
|
|
@@ -177,6 +180,7 @@ export default class FormControl {
|
|
|
177
180
|
error.classList.remove(this._options.classIsError);
|
|
178
181
|
error.parentNode.removeChild(error);
|
|
179
182
|
});
|
|
183
|
+
el.removeAttribute('aria-describedby');
|
|
180
184
|
} else {
|
|
181
185
|
const isErrors = [...this._form.querySelectorAll(`${this._options.classIsError}`)];
|
|
182
186
|
const currentErrors = [...this._form.querySelectorAll(`.${this._options.classErrorElement}`)];
|
|
@@ -186,6 +190,9 @@ export default class FormControl {
|
|
|
186
190
|
isErrors.forEach(error => {
|
|
187
191
|
error.classList.remove(this._options.classIsError);
|
|
188
192
|
});
|
|
193
|
+
this._domForm.els.forEach( input => {
|
|
194
|
+
input.removeAttribute('aria-describedby');
|
|
195
|
+
});
|
|
189
196
|
}
|
|
190
197
|
}
|
|
191
198
|
|