aw-front-helpers 2.5.4 → 2.5.5
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 +39 -22
- package/package.json +2 -2
package/classes/formControl.js
CHANGED
|
@@ -100,25 +100,39 @@ export default class FormControl {
|
|
|
100
100
|
|
|
101
101
|
setError(element, message = null) {
|
|
102
102
|
const parent = element.closest(this._options.selectorGroup);
|
|
103
|
-
if(
|
|
103
|
+
if (parent === null) return;
|
|
104
104
|
let error = parent.querySelector(`.${this._options.classErrorElement}`);
|
|
105
|
+
parent.classList.add(this._options.classIsError);
|
|
105
106
|
if (!error) {
|
|
106
107
|
error = Object.assign(
|
|
107
|
-
document.createElement('
|
|
108
|
-
className: this._options.classErrorElement
|
|
108
|
+
document.createElement('p'), {
|
|
109
|
+
className: this._options.classErrorElement,
|
|
110
|
+
innerHTML: message
|
|
109
111
|
});
|
|
112
|
+
error.setAttribute('aria-describedby', element.id);
|
|
110
113
|
parent.appendChild(error);
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
114
|
+
} else {
|
|
115
|
+
if (error.tagName === 'P') {
|
|
116
|
+
if (message === error.innerHTML) return;
|
|
117
|
+
const newError = Object.assign(
|
|
118
|
+
document.createElement('ul'), {
|
|
119
|
+
className: this._options.classErrorElement,
|
|
120
|
+
innerHTML: `<li>${error.innerHTML}</li>`
|
|
121
|
+
});
|
|
122
|
+
newError.setAttribute('aria-describedby', element.id);
|
|
123
|
+
parent.appendChild(newError);
|
|
124
|
+
error.parentNode.removeChild(error);
|
|
125
|
+
error = newError;
|
|
126
|
+
}
|
|
127
|
+
const previousErrors = [...error.querySelectorAll('li')];
|
|
128
|
+
for (let i = 0; i < previousErrors.length; i++) {
|
|
129
|
+
if (previousErrors[i].innerHTML === message) return;
|
|
130
|
+
}
|
|
131
|
+
if (message) {
|
|
132
|
+
const errorElement = document.createElement('li');
|
|
133
|
+
errorElement.innerHTML = message;
|
|
134
|
+
error.appendChild(errorElement);
|
|
135
|
+
}
|
|
122
136
|
}
|
|
123
137
|
}
|
|
124
138
|
|
|
@@ -149,14 +163,14 @@ export default class FormControl {
|
|
|
149
163
|
/** @private */
|
|
150
164
|
_formCreateBound() {
|
|
151
165
|
['_onChange', '_onFormSubmit', 'onFormSubmit']
|
|
152
|
-
|
|
166
|
+
.forEach((fn) => this[fn] = this[fn].bind(this));
|
|
153
167
|
}
|
|
154
168
|
|
|
155
169
|
/** @private */
|
|
156
170
|
_removeError(el = null) {
|
|
157
171
|
if (el) {
|
|
158
|
-
const group = el.closest(
|
|
159
|
-
if(
|
|
172
|
+
const group = el.closest(this._options.selectorGroup);
|
|
173
|
+
if (group === null) return;
|
|
160
174
|
group.classList.remove(this._options.classIsError);
|
|
161
175
|
const currentErrors = [...group.querySelectorAll(`.${this._options.classErrorElement}`)];
|
|
162
176
|
currentErrors.forEach(error => {
|
|
@@ -219,11 +233,14 @@ export default class FormControl {
|
|
|
219
233
|
if (!isValid && firstErrorElement === null) firstErrorElement = el;
|
|
220
234
|
}
|
|
221
235
|
|
|
222
|
-
if (!isValid && firstErrorElement
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
236
|
+
if (!isValid && firstErrorElement) {
|
|
237
|
+
firstErrorElement.focus();
|
|
238
|
+
if (this._options.animateToFirstError) {
|
|
239
|
+
gsap.to(window, {
|
|
240
|
+
duration: .6,
|
|
241
|
+
scrollTo: (window.pageYOffset + firstErrorElement.getBoundingClientRect().top - 150)
|
|
242
|
+
})
|
|
243
|
+
}
|
|
227
244
|
}
|
|
228
245
|
return isValid;
|
|
229
246
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "aw-front-helpers",
|
|
3
|
-
"version": "2.5.
|
|
3
|
+
"version": "2.5.5",
|
|
4
4
|
"description": "Assets helpers for projects",
|
|
5
5
|
"author": "Yoann Le Poupon",
|
|
6
6
|
"license": "ISC",
|
|
@@ -12,6 +12,6 @@
|
|
|
12
12
|
"dependencies": {
|
|
13
13
|
"es6-symbol": "^3.1.3",
|
|
14
14
|
"exif-js": "^2.3.0",
|
|
15
|
-
"gsap": "^3.
|
|
15
|
+
"gsap": "^3.12.1"
|
|
16
16
|
}
|
|
17
17
|
}
|