aw-front-helpers 2.5.24 → 2.5.25
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 +42 -0
- package/package.json +1 -1
package/classes/formControl.js
CHANGED
|
@@ -27,6 +27,12 @@ const defaultOptions = {
|
|
|
27
27
|
radio: window.Translator
|
|
28
28
|
? window.Translator.trans('form_errors.radio')
|
|
29
29
|
: 'Veuillez sélectionner au moins un choix.',
|
|
30
|
+
minLength: window.Translator
|
|
31
|
+
? window.Translator.trans('form_errors.min_length')
|
|
32
|
+
: 'Ce champ doit contenir au minimum %length% caractères',
|
|
33
|
+
maxLength: window.Translator
|
|
34
|
+
? window.Translator.trans('form_errors.max_length')
|
|
35
|
+
: 'Ce champ doit contenir au maximum %length% caractères',
|
|
30
36
|
pattern: window.Translator
|
|
31
37
|
? window.Translator.trans('form_errors.pattern')
|
|
32
38
|
: 'La donnée saisie ne respecte pas les règles énoncées.',
|
|
@@ -267,6 +273,16 @@ export default class FormControl {
|
|
|
267
273
|
invalid = true;
|
|
268
274
|
this.setError(el, this._options.i18n.same);
|
|
269
275
|
}
|
|
276
|
+
if (!testMinLength(el, this._form)) {
|
|
277
|
+
invalid = true;
|
|
278
|
+
const minLength = el.getAttribute('minlength');
|
|
279
|
+
this.setError(el, this._options.i18n.minLength.replace('%length%', minLength));
|
|
280
|
+
}
|
|
281
|
+
if (!testMaxLength(el, this._form)) {
|
|
282
|
+
invalid = true;
|
|
283
|
+
const maxLength = el.getAttribute('maxlength');
|
|
284
|
+
this.setError(el, this._options.i18n.maxLength.replace('%length%', maxLength));
|
|
285
|
+
}
|
|
270
286
|
if( el.specialControls ) {
|
|
271
287
|
for( let key in el.specialControls ) {
|
|
272
288
|
if( !el.specialControls[key].isValid() ) {
|
|
@@ -361,6 +377,32 @@ export function testRequired(el, form) {
|
|
|
361
377
|
return el.value !== '';
|
|
362
378
|
}
|
|
363
379
|
|
|
380
|
+
/**
|
|
381
|
+
* Test required input minlength is valid
|
|
382
|
+
* @param {Element} el Input to test
|
|
383
|
+
* @param {Element} form Formulaire
|
|
384
|
+
* @return {Boolean} Returns if element is valid or not
|
|
385
|
+
*/
|
|
386
|
+
export function testMinLength(el, form) {
|
|
387
|
+
const minLength = el.getAttribute('minlength');
|
|
388
|
+
if (minLength === null) return true;
|
|
389
|
+
const value = el.value.trim();
|
|
390
|
+
return value === '' || (value !== '' && value.length >= parseInt(minLength))
|
|
391
|
+
}
|
|
392
|
+
|
|
393
|
+
/**
|
|
394
|
+
* Test required input maxlength is valid
|
|
395
|
+
* @param {Element} el Input to test
|
|
396
|
+
* @param {Element} form Formulaire
|
|
397
|
+
* @return {Boolean} Returns if element is valid or not
|
|
398
|
+
*/
|
|
399
|
+
export function testMaxLength(el, form) {
|
|
400
|
+
const maxLength = el.getAttribute('maxlength');
|
|
401
|
+
if (maxLength === null) return true;
|
|
402
|
+
const value = el.value.trim();
|
|
403
|
+
return value === '' || (value !== '' && value.length <= parseInt(maxLength))
|
|
404
|
+
}
|
|
405
|
+
|
|
364
406
|
/**
|
|
365
407
|
* Test input of email type is valid
|
|
366
408
|
* @param {Element} el Input to test
|