aw-front-helpers 2.3.9 → 2.4.0
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 +207 -109
- package/package.json +1 -1
- package/utils/media/autoplay.js +4 -21
package/classes/formControl.js
CHANGED
|
@@ -1,9 +1,7 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import ScrollToPlugin
|
|
1
|
+
import { gsap } from 'gsap/all';
|
|
2
|
+
import ScrollToPlugin from 'gsap/ScrollToPlugin';
|
|
3
3
|
gsap.registerPlugin( ScrollToPlugin );
|
|
4
|
-
|
|
5
4
|
import create from 'dom-create-element';
|
|
6
|
-
|
|
7
5
|
import getClosest from '../utils/dom/getClosest';
|
|
8
6
|
import regex_email from '../utils/regex/email';
|
|
9
7
|
|
|
@@ -11,27 +9,48 @@ const defaultOptions = {
|
|
|
11
9
|
selectorGroup: '.form-group',
|
|
12
10
|
classErrorElement: 'form-error',
|
|
13
11
|
classIsError: 'is-error',
|
|
14
|
-
animateToFirstError:
|
|
12
|
+
animateToFirstError: false,
|
|
15
13
|
i18n: {
|
|
16
|
-
|
|
14
|
+
required: Translator ? Translator.trans('form_errors.pattern') : 'Ce champs est obligatoire',
|
|
17
15
|
same: Translator ? Translator.trans('form_errors.same') : 'Les champs ne correspondent pas.',
|
|
16
|
+
email: Translator ? Translator.trans('form_errors.email') : 'Merci de renseigner un email valide.',
|
|
18
17
|
empty: Translator ? Translator.trans('form_errors.empty') : 'Ce champs est obligatoire.',
|
|
19
18
|
checkbox: Translator ? Translator.trans('form_errors.checkbox') : 'Veuillez accepter les conditions.',
|
|
20
|
-
radio: Translator ? Translator.trans('form_errors.radio') : 'Veuillez sélectionner au moins un choix.'
|
|
19
|
+
radio: Translator ? Translator.trans('form_errors.radio') : 'Veuillez sélectionner au moins un choix.',
|
|
20
|
+
pattern: Translator ? Translator.trans('form_errors.pattern') : 'La donnée saisie ne respecte pas les règles énoncées.',
|
|
21
21
|
}
|
|
22
22
|
};
|
|
23
23
|
|
|
24
|
-
class FormControl {
|
|
24
|
+
export default class FormControl {
|
|
25
25
|
//________________________________________________________ constructor
|
|
26
26
|
// -
|
|
27
|
-
|
|
28
|
-
|
|
27
|
+
/**
|
|
28
|
+
* Add controls on your formulaire
|
|
29
|
+
* @param {Element} form formulaire need add control
|
|
30
|
+
* @param {Object} options define options of controls
|
|
31
|
+
* @param {string} options.selectorGroup - The name of the employee.
|
|
32
|
+
* @param {string} options.classErrorElement - The employee's department.
|
|
33
|
+
* @param {string} options.classIsError - The employee's department.
|
|
34
|
+
* @param {string} options.animateToFirstError - The employee's department.
|
|
35
|
+
* @param {Object} options.i18n - The employee's department.
|
|
36
|
+
* @param {Object} options.i18n.required - The employee's department.
|
|
37
|
+
* @param {Object} options.i18n.same - The employee's department.
|
|
38
|
+
* @param {Object} options.i18n.email - The employee's department.
|
|
39
|
+
* @param {Object} options.i18n.empty - The employee's department.
|
|
40
|
+
* @param {Object} options.i18n.checkbox - The employee's department.
|
|
41
|
+
* @param {Object} options.i18n.radio - The employee's department.
|
|
42
|
+
* @param {Object} options.i18n.pattern - The employee's department.
|
|
43
|
+
**/
|
|
44
|
+
constructor(form, options = {}) {
|
|
45
|
+
/** @private */
|
|
46
|
+
this._form = form;
|
|
47
|
+
/** @private */
|
|
29
48
|
this._dom = {};
|
|
49
|
+
/** @private */
|
|
30
50
|
this._options = {...defaultOptions, ...options};
|
|
31
51
|
|
|
52
|
+
this._form.setAttribute('novalidate', 'novalidate');
|
|
32
53
|
this._formCreateBound();
|
|
33
|
-
this._el.setAttribute('novalidate', 'novalidate');
|
|
34
|
-
|
|
35
54
|
this._formGrabDom();
|
|
36
55
|
this._formAddEvents();
|
|
37
56
|
}
|
|
@@ -43,39 +62,41 @@ class FormControl {
|
|
|
43
62
|
};
|
|
44
63
|
}
|
|
45
64
|
|
|
65
|
+
get form() {
|
|
66
|
+
return this._form;
|
|
67
|
+
}
|
|
68
|
+
|
|
46
69
|
get options() {
|
|
47
70
|
return this._options;
|
|
48
71
|
}
|
|
49
72
|
|
|
73
|
+
/**
|
|
74
|
+
* @deprecated use isValid
|
|
75
|
+
*/
|
|
50
76
|
get isValidate() {
|
|
51
|
-
return this.
|
|
77
|
+
return this._isValid();
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
get isValid() {
|
|
81
|
+
return this._isValid();
|
|
52
82
|
}
|
|
53
83
|
|
|
54
84
|
//________________________________________________________ public
|
|
55
85
|
// -
|
|
56
86
|
destroy() {
|
|
57
|
-
this.
|
|
87
|
+
this._form.removeEventListener('submit', this._onFormSubmit);
|
|
58
88
|
this._domForm.inputs.forEach( input => {
|
|
59
|
-
input.removeEventListener('keyup', this.
|
|
60
|
-
if (input.getAttribute('type') === 'checkbox' ||
|
|
61
|
-
input.getAttribute('type') === 'radio' ||
|
|
62
|
-
input.tagName === 'SELECT') {
|
|
63
|
-
input.removeEventListener('change', this._onFormKeyUp);
|
|
64
|
-
}
|
|
65
|
-
})
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
removeErrors() {
|
|
69
|
-
const isErrors = [...this._el.querySelectorAll(`${this._options.classIsError}`)];
|
|
70
|
-
const currentErrors = [...this._el.querySelectorAll(`.${this._options.classErrorElement}`)];
|
|
71
|
-
currentErrors.forEach(error => {
|
|
72
|
-
error.parentNode.removeChild(error);
|
|
89
|
+
input.removeEventListener('keyup', this._onChange);
|
|
73
90
|
});
|
|
74
|
-
|
|
75
|
-
|
|
91
|
+
this._domForm.choices.forEach( input => {
|
|
92
|
+
input.removeEventListener('change', this._onChange);
|
|
76
93
|
});
|
|
77
94
|
}
|
|
78
95
|
|
|
96
|
+
removeErrors(el = null) {
|
|
97
|
+
this._removeError(el);
|
|
98
|
+
}
|
|
99
|
+
|
|
79
100
|
setError(element, message = null) {
|
|
80
101
|
const parent = getClosest(element, this._options.selectorGroup);
|
|
81
102
|
if( parent) {
|
|
@@ -88,6 +109,11 @@ class FormControl {
|
|
|
88
109
|
parent.appendChild(error);
|
|
89
110
|
}
|
|
90
111
|
parent.classList.add(this._options.classIsError);
|
|
112
|
+
|
|
113
|
+
const previousErrors = [...error.querySelectorAll('li')];
|
|
114
|
+
for(let i = 0; i < previousErrors.length; i++) {
|
|
115
|
+
if(previousErrors[i].innerHTML === message) return;
|
|
116
|
+
}
|
|
91
117
|
if(message) {
|
|
92
118
|
const errorElement = document.createElement('li');
|
|
93
119
|
errorElement.innerHTML = message;
|
|
@@ -98,105 +124,177 @@ class FormControl {
|
|
|
98
124
|
|
|
99
125
|
//________________________________________________________ events
|
|
100
126
|
// -
|
|
127
|
+
/** @private */
|
|
101
128
|
_onFormSubmit(pEvt) {
|
|
102
|
-
if (!this.
|
|
129
|
+
if (!this._isValid()) {
|
|
103
130
|
pEvt.preventDefault();
|
|
104
131
|
}
|
|
105
132
|
}
|
|
106
133
|
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
const currentErrors = [...parent.querySelectorAll(`.${this._options.classErrorElement}`)];
|
|
112
|
-
currentErrors.forEach(error => {
|
|
113
|
-
error.classList.remove(this._options.classIsError);
|
|
114
|
-
error.parentNode.removeChild(error);
|
|
115
|
-
});
|
|
134
|
+
/** @private */
|
|
135
|
+
_onChange(pEvt) {
|
|
136
|
+
const el = pEvt.target;
|
|
137
|
+
this._removeError(el);
|
|
116
138
|
}
|
|
117
139
|
|
|
118
140
|
//________________________________________________________ private
|
|
119
141
|
// -
|
|
142
|
+
/** @private */
|
|
120
143
|
_formCreateBound() {
|
|
121
|
-
['
|
|
144
|
+
['_onChange', '_onFormSubmit']
|
|
122
145
|
.forEach((fn) => this[fn] = this[fn].bind(this));
|
|
123
146
|
}
|
|
124
147
|
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
for (let i = 0; i < this._domForm.inputs.length; i++) {
|
|
145
|
-
let el = this._domForm.inputs[i],
|
|
146
|
-
parent = getClosest(el, this._options.selectorGroup);
|
|
147
|
-
if (parent === null) continue;
|
|
148
|
-
if (el.getAttribute('disabled')) continue;
|
|
149
|
-
if (el.getAttribute('type') && el.getAttribute('type') === 'email' && (!regex_email(el.value) && el.value !== '')) {
|
|
150
|
-
validate = false;
|
|
151
|
-
this.setError(el, this._options.i18n.email);
|
|
152
|
-
}
|
|
153
|
-
if (el.getAttribute('data-formvalidate-same') && this._el.querySelector(`[data-formvalidate-same=${el.getAttribute('data-formvalidate-same')}]`).value !== el.value) {
|
|
154
|
-
validate = false;
|
|
155
|
-
this.setError(el, this._options.i18n.same);
|
|
156
|
-
}
|
|
157
|
-
if (el.getAttribute('required') !== null) {
|
|
158
|
-
if (el.getAttribute('type') === 'radio') {
|
|
159
|
-
let isChecked = false;
|
|
160
|
-
let els = [...this._el.querySelectorAll(`input[type="radio"][name="${el.getAttribute('name')}"]`)];
|
|
161
|
-
for (let i = 0; i < els.length; i++) {
|
|
162
|
-
if (els[i].checked) {
|
|
163
|
-
isChecked = true;
|
|
164
|
-
break;
|
|
165
|
-
}
|
|
166
|
-
}
|
|
167
|
-
if (!isChecked) {
|
|
168
|
-
validate = false;
|
|
169
|
-
this.setError(el, this._options.i18n.radio);
|
|
170
|
-
}
|
|
171
|
-
}
|
|
172
|
-
if (el.getAttribute('type') === 'checkbox' && !el.checked) {
|
|
173
|
-
validate = false;
|
|
174
|
-
this.setError(el, this._options.i18n.checkbox);
|
|
175
|
-
} else if (el.value === '') {
|
|
176
|
-
validate = false;
|
|
177
|
-
const message = el.getAttribute('type') !== 'hidden' ? this._options.i18n.empty : null;
|
|
178
|
-
this.setError(el, message);
|
|
179
|
-
}
|
|
180
|
-
}
|
|
181
|
-
if (!validate && errorEl === null) errorEl = el;
|
|
148
|
+
/** @private */
|
|
149
|
+
_removeError(el = null) {
|
|
150
|
+
if(el) {
|
|
151
|
+
const group = getClosest(el, this._options.selectorGroup);
|
|
152
|
+
group.classList.remove(this._options.classIsError);
|
|
153
|
+
const currentErrors = [...group.querySelectorAll(`.${this._options.classErrorElement}`)];
|
|
154
|
+
currentErrors.forEach(error => {
|
|
155
|
+
error.classList.remove(this._options.classIsError);
|
|
156
|
+
error.parentNode.removeChild(error);
|
|
157
|
+
});
|
|
158
|
+
} else {
|
|
159
|
+
const isErrors = [...this._form.querySelectorAll(`${this._options.classIsError}`)];
|
|
160
|
+
const currentErrors = [...this._form.querySelectorAll(`.${this._options.classErrorElement}`)];
|
|
161
|
+
currentErrors.forEach(error => {
|
|
162
|
+
error.parentNode.removeChild(error);
|
|
163
|
+
});
|
|
164
|
+
isErrors.forEach(error => {
|
|
165
|
+
error.classList.remove(this._options.classIsError);
|
|
166
|
+
});
|
|
182
167
|
}
|
|
183
|
-
|
|
184
|
-
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
/** @private */
|
|
171
|
+
_checkError(el) {
|
|
172
|
+
const group = getClosest(el, this._options.selectorGroup);
|
|
173
|
+
if (group === null) return false;
|
|
174
|
+
if (el.getAttribute('disabled') !== null) return false;
|
|
175
|
+
|
|
176
|
+
let invalid = false;
|
|
177
|
+
if( !testRequired(el, this._form) ) {
|
|
178
|
+
invalid = true;
|
|
179
|
+
const type = el.getAttribute('type');
|
|
180
|
+
if(type === 'radio') this.setError(el, this._options.i18n.radio);
|
|
181
|
+
else if(type === 'checkbox') this.setError(el, this._options.i18n.checkbox);
|
|
182
|
+
else if(type !== 'hidden') this.setError(el, this._options.i18n.empty);
|
|
185
183
|
}
|
|
186
|
-
|
|
184
|
+
if( !testEmail(el, this._form) ) {
|
|
185
|
+
invalid = true;
|
|
186
|
+
this.setError(el, this._options.i18n.email);
|
|
187
|
+
}
|
|
188
|
+
if( !testPattern(el, this._form) ) {
|
|
189
|
+
invalid = true;
|
|
190
|
+
this.setError(el, this._options.i18n.pattern);
|
|
191
|
+
}
|
|
192
|
+
if( !testSame(el, this._form) ) {
|
|
193
|
+
invalid = true;
|
|
194
|
+
this.setError(el, this._options.i18n.same);
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
return invalid;
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
/** @private */
|
|
201
|
+
_isValid() {
|
|
202
|
+
let isValid = true, firstErrorElement = null;
|
|
203
|
+
this._removeError();
|
|
204
|
+
|
|
205
|
+
for (let i = 0; i < this._domForm.els.length; i++) {
|
|
206
|
+
const el = this._domForm.els[i];
|
|
207
|
+
const error = this._checkError(el);
|
|
208
|
+
if( !error ) continue;
|
|
209
|
+
else isValid = false;
|
|
210
|
+
if (!isValid && firstErrorElement === null) firstErrorElement = el;
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
if (!isValid && firstErrorElement && this._options.animateToFirstError) {
|
|
214
|
+
gsap.to(window, {
|
|
215
|
+
duration: .6,
|
|
216
|
+
scrollTo: (window.pageYOffset + firstErrorElement.getBoundingClientRect().top - 150)
|
|
217
|
+
})
|
|
218
|
+
}
|
|
219
|
+
return isValid;
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
/** @private */
|
|
223
|
+
_formGrabDom() {
|
|
224
|
+
/** @private */
|
|
225
|
+
this._domForm = {};
|
|
226
|
+
this._domForm.inputs = [...this._form.querySelectorAll('input[type=text],input[type=number],input[type=password],input[type=hidden],input[type=search],input[type=email],input[type=email],input[type=tel],textarea')];
|
|
227
|
+
this._domForm.choices = [...this._form.querySelectorAll('select, input[type=radio],input[type=checkbox]')];
|
|
228
|
+
this._domForm.els = [...this._domForm.inputs, ...this._domForm.choices];
|
|
187
229
|
}
|
|
188
230
|
|
|
231
|
+
/** @private */
|
|
189
232
|
_formAddEvents() {
|
|
190
|
-
this.
|
|
233
|
+
this._form.addEventListener('submit', this._onFormSubmit);
|
|
191
234
|
this._domForm.inputs.forEach( input => {
|
|
192
|
-
input.addEventListener('keyup', this.
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
input.addEventListener('change', this._onFormKeyUp);
|
|
197
|
-
}
|
|
235
|
+
input.addEventListener('keyup', this._onChange);
|
|
236
|
+
});
|
|
237
|
+
this._domForm.choices.forEach( input => {
|
|
238
|
+
input.addEventListener('change', this._onChange);
|
|
198
239
|
});
|
|
199
240
|
}
|
|
200
241
|
}
|
|
201
242
|
|
|
202
|
-
|
|
243
|
+
/**
|
|
244
|
+
* Test required input/radio/checkbox is valid
|
|
245
|
+
* @param {Element} el Input to test
|
|
246
|
+
* @param {Element} form Formulaire
|
|
247
|
+
* @return {Boolean} Returns if element is valid or not
|
|
248
|
+
*/
|
|
249
|
+
export function testRequired(el, form) {
|
|
250
|
+
const isRequired = el.getAttribute('required');
|
|
251
|
+
if (isRequired === null) return true;
|
|
252
|
+
|
|
253
|
+
const type = el.getAttribute('type');
|
|
254
|
+
if(type === 'radio') {
|
|
255
|
+
const radios = [...form.querySelectorAll(`input[type="radio"][name="${el.getAttribute('name')}"]`)];
|
|
256
|
+
for (let i = 0; i < radios.length; i++) {
|
|
257
|
+
if (radios[i].checked) return true;
|
|
258
|
+
}
|
|
259
|
+
return false;
|
|
260
|
+
} else if( type === 'checkbox') return el.checked;
|
|
261
|
+
return el.value !== '';
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
/**
|
|
265
|
+
* Test input of email type is valid
|
|
266
|
+
* @param {Element} el Input to test
|
|
267
|
+
* @param {Element} form Formulaire
|
|
268
|
+
* @return {Boolean} Returns if element is valid or not
|
|
269
|
+
*/
|
|
270
|
+
export function testEmail(el, form) {
|
|
271
|
+
const type = el.getAttribute('type');
|
|
272
|
+
if(type !== 'email') return true;
|
|
273
|
+
return el.value === '' && !regex_email(el.value);
|
|
274
|
+
}
|
|
275
|
+
|
|
276
|
+
/**
|
|
277
|
+
* Test element with attribute data-formvalidate-same and his twin are same
|
|
278
|
+
* @param {Element} el Input to test
|
|
279
|
+
* @param {Element} form Formulaire
|
|
280
|
+
* @return {Boolean} Returns if element is valid or not
|
|
281
|
+
*/
|
|
282
|
+
export function testSame(el, form) {
|
|
283
|
+
const hasSame = el.getAttribute('data-formvalidate-same');
|
|
284
|
+
if(hasSame === null) return true;
|
|
285
|
+
const twinEl = form.querySelector(`[data-formvalidate-same=${el.getAttribute('data-formvalidate-same')}]`);
|
|
286
|
+
return twinEl.value === el.value;
|
|
287
|
+
}
|
|
288
|
+
|
|
289
|
+
/**
|
|
290
|
+
* Test element with pattern is valid
|
|
291
|
+
* @param {Element} el Input to test
|
|
292
|
+
* @param {Element} form Formulaire
|
|
293
|
+
* @return {Boolean} Returns if element is valid or not
|
|
294
|
+
*/
|
|
295
|
+
export function testPattern(el, form) {
|
|
296
|
+
const pattern = el.getAttribute('pattern');
|
|
297
|
+
if(pattern === null) return true;
|
|
298
|
+
const rgx = new RegExp(pattern);
|
|
299
|
+
return el.value === '' && !rgx.test(el.value);
|
|
300
|
+
}
|
package/package.json
CHANGED
package/utils/media/autoplay.js
CHANGED
|
@@ -1,13 +1,9 @@
|
|
|
1
1
|
export default (callback) => {
|
|
2
|
-
// Is the callback a function?
|
|
3
2
|
if (typeof callback !== 'function') {
|
|
4
|
-
console.
|
|
3
|
+
console.warn('Autoplay: Callback must be a function!');
|
|
5
4
|
return false;
|
|
6
5
|
}
|
|
7
|
-
// Check if sessionStorage exist for autoplaySupported,
|
|
8
|
-
// if so we don't need to check for support again
|
|
9
6
|
if (!sessionStorage.autoplaySupported) {
|
|
10
|
-
// Create video element to test autoplay
|
|
11
7
|
var video = document.createElement('video');
|
|
12
8
|
video.autoplay = true;
|
|
13
9
|
video.src = 'data:video/mp4;base64,AAAAIGZ0eXBtcDQyAAAAAG1wNDJtcDQxaXNvbWF2YzEAAATKbW9vdgAAAGxtdmhkAAAAANLEP5XSxD+VAAB1MAAAdU4AAQAAAQAAAAAAAAAAAAAAAAEAAAAAAAAAAAAAAAAAAAABAAAAAAAAAAA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AAAAXQZs0SahBbJlMCCv//rUqgAAAAwAAHVAAAAARQZ9SRRUsFf8AAAMAAAMADpkAAAAPAZ9xdEFfAAADAAADAA6YAAAADwGfc2pBXwAAAwAAAwAOmAAAABdBm3hJqEFsmUwIK//+tSqAAAADAAAdUQAAABFBn5ZFFSwV/wAAAwAAAwAOmAAAAA8Bn7V0QV8AAAMAAAMADpkAAAAPAZ+3akFfAAADAAADAA6ZAAAAF0GbvEmoQWyZTAgr//61KoAAAAMAAB1QAAAAEUGf2kUVLBX/AAADAAADAA6ZAAAADwGf+XRBXwAAAwAAAwAOmAAAAA8Bn/tqQV8AAAMAAAMADpkAAAAXQZv9SahBbJlMCCv//rUqgAAAAwAAHVE=';
|
|
@@ -15,27 +11,14 @@ export default (callback) => {
|
|
|
15
11
|
video.style.display = 'none';
|
|
16
12
|
video.playing = false;
|
|
17
13
|
video.play();
|
|
18
|
-
// Check if video plays
|
|
19
14
|
video.onplay = function () {
|
|
20
15
|
this.playing = true;
|
|
21
16
|
};
|
|
22
|
-
// Video has loaded, check autoplay support
|
|
23
17
|
video.oncanplay = function () {
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
callback(true);
|
|
27
|
-
} else {
|
|
28
|
-
sessionStorage.autoplaySupported = 'false';
|
|
29
|
-
callback(false);
|
|
30
|
-
}
|
|
18
|
+
sessionStorage.autoplaySupported = video.playing ? 'true' : 'false';
|
|
19
|
+
callback(video.playing);
|
|
31
20
|
};
|
|
32
21
|
} else {
|
|
33
|
-
|
|
34
|
-
// use sessionStorage.autoplaySupported
|
|
35
|
-
if (sessionStorage.autoplaySupported === 'true') {
|
|
36
|
-
callback(true);
|
|
37
|
-
} else {
|
|
38
|
-
callback(false);
|
|
39
|
-
}
|
|
22
|
+
callback(sessionStorage.autoplaySupported === 'true');
|
|
40
23
|
}
|
|
41
24
|
}
|