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.
@@ -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
- className: this._options.classErrorElement,
110
- innerHTML: message
110
+ id,
111
+ className: this._options.classErrorElement,
112
+ innerHTML: message
111
113
  });
112
- error.setAttribute('aria-describedby', element.id);
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
- className: this._options.classErrorElement,
120
- innerHTML: `<li>${error.innerHTML}</li>`
121
+ id,
122
+ className: this._options.classErrorElement,
123
+ innerHTML: `<li>${error.innerHTML}</li>`
121
124
  });
122
- newError.setAttribute('aria-describedby', element.id);
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
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "aw-front-helpers",
3
- "version": "2.5.5",
3
+ "version": "2.5.7",
4
4
  "description": "Assets helpers for projects",
5
5
  "author": "Yoann Le Poupon",
6
6
  "license": "ISC",