@@ -274,7 +274,8 @@ function _defineProperty(obj, key, value) { if (key in obj) { Object.definePrope
274
274
RULE_PASSWORD = 'password' ,
275
275
RULE_ZIP = 'zip' ,
276
276
RULE_PHONE = 'phone' ,
277
- RULE_REMOTE = 'remote' ;
277
+ RULE_REMOTE = 'remote' ,
278
+ RULE_STRENGTH = 'strength' ;
278
279
279
280
var formatParams = function formatParams ( params , method ) {
280
281
if ( typeof params === 'string' ) {
@@ -336,6 +337,10 @@ function _defineProperty(obj, key, value) { if (key in obj) { Object.definePrope
336
337
this . colorWrong = this . options . colorWrong || '#B81111' ;
337
338
this . result = { } ;
338
339
this . elements = [ ] ;
340
+ this . tooltip = this . options . tooltip || { } ;
341
+ this . tooltipFadeOutTime = this . tooltip . fadeOutTime || 5000 ;
342
+ this . tooltipFadeOutClass = this . tooltip . fadeOutClass || 'just-validate-tooltip-hide' ;
343
+ this . tooltipSelectorWrap = document . querySelectorAll ( this . tooltip . selectorWrap ) . length ? document . querySelectorAll ( this . tooltip . selectorWrap ) : document . querySelectorAll ( '.just-validate-tooltip-container' ) ;
339
344
this . bindHandlerKeyup = this . handlerKeyup . bind ( this ) ;
340
345
this . submitHandler = this . options . submitHandler || undefined ;
341
346
this . promisesRemote = [ ] ;
@@ -345,9 +350,13 @@ function _defineProperty(obj, key, value) { if (key in obj) { Object.definePrope
345
350
email : / ^ ( ( [ ^ < > ( ) \[ \] \\ . , ; : \s @ " ] + ( \. [ ^ < > ( ) \[ \] \\ . , ; : \s @ " ] + ) * ) | ( " .+ " ) ) @ ( ( \[ [ 0 - 9 ] { 1 , 3 } \. [ 0 - 9 ] { 1 , 3 } \. [ 0 - 9 ] { 1 , 3 } \. [ 0 - 9 ] { 1 , 3 } ] ) | ( ( [ a - z A - Z \- 0 - 9 ] + \. ) + [ a - z A - Z ] { 2 , } ) ) $ / ,
346
351
zip : / ^ \d { 5 } ( - \d { 4 } ) ? $ / ,
347
352
phone : / ^ ( [ 0 - 9 ] ( | - ) ? ) ? ( \( ? [ 0 - 9 ] { 3 } \) ? | [ 0 - 9 ] { 3 } ) ( | - ) ? ( [ 0 - 9 ] { 3 } ( | - ) ? [ 0 - 9 ] { 4 } | [ a - z A - Z 0 - 9 ] { 7 } ) $ / ,
348
- password : / [ ^ \w \d ] * ( ( [ 0 - 9 ] + .* [ A - Z a - z ] + .* ) | [ A - Z a - z ] + .* ( [ 0 - 9 ] + .* ) ) /
353
+ password : / [ ^ \w \d ] * ( ( [ 0 - 9 ] + .* [ A - Z a - z ] + .* ) | [ A - Z a - z ] + .* ( [ 0 - 9 ] + .* ) ) / ,
354
+ strengthPass : / ^ (? = .* [ a - z ] ) (? = .* [ A - Z ] ) (? = .* \d ) [ a - z A - Z \d ] /
349
355
} ;
350
356
this . DEFAULT_REMOTE_ERROR = 'Error' ;
357
+ this . state = {
358
+ tooltipsTimer : null
359
+ } ;
351
360
352
361
this . setForm ( document . querySelector ( selector ) ) ;
353
362
} ;
@@ -389,7 +398,8 @@ function _defineProperty(obj, key, value) { if (key in obj) { Object.definePrope
389
398
maxLength : 'The field must contain a maximum of :value characters' ,
390
399
minLength : 'The field must contain a minimum of :value characters' ,
391
400
password : 'Password is not valid' ,
392
- remote : 'Email already exists'
401
+ remote : 'Email already exists' ,
402
+ strength : 'Password must contents at least one uppercase letter, one lowercase letter and one number'
393
403
} ,
394
404
/**
395
405
* Keyup handler
@@ -518,6 +528,10 @@ function _defineProperty(obj, key, value) { if (key in obj) { Object.definePrope
518
528
return text . length >= min ;
519
529
} ,
520
530
531
+ checkStrengthPass : function checkStrengthPass ( password ) {
532
+ return this . REGEXP . strengthPass . test ( password ) ;
533
+ } ,
534
+
521
535
getElements : function getElements ( ) {
522
536
var _this2 = this ;
523
537
@@ -605,6 +619,15 @@ function _defineProperty(obj, key, value) { if (key in obj) { Object.definePrope
605
619
return this . checkLengthMax ( value , max ) ;
606
620
} ,
607
621
622
+ /**
623
+ * Validate field for strength password
624
+ * @param {string } password Value for validate
625
+ * @returns {boolean } True if validate is OK
626
+ */
627
+ validateStrengthPass : function validateStrengthPass ( password ) {
628
+ return this . checkStrengthPass ( password ) ;
629
+ } ,
630
+
608
631
/**
609
632
* Validate Password field
610
633
* @param {string } value Value for validate
@@ -798,6 +821,36 @@ function _defineProperty(obj, key, value) { if (key in obj) { Object.definePrope
798
821
return ;
799
822
}
800
823
824
+ case RULE_STRENGTH :
825
+ {
826
+ if ( ! ruleValue || ( typeof ruleValue === 'undefined' ? 'undefined' : _typeof ( ruleValue ) ) !== 'object' ) {
827
+ break ;
828
+ }
829
+
830
+ if ( ruleValue . default && this . validateStrengthPass ( value ) ) {
831
+ break ;
832
+ }
833
+
834
+ if ( ruleValue . custom ) {
835
+ var regexp = void 0 ;
836
+
837
+ try {
838
+ regexp = new RegExp ( ruleValue . custom ) ;
839
+ } catch ( e ) {
840
+ regexp = this . REGEXP . strengthPass ;
841
+
842
+ // eslint-disable-next-line no-console
843
+ console . error ( 'Custom regexp for strength rule is not valid. Default regexp was used.' ) ;
844
+ }
845
+
846
+ if ( regexp . test ( value ) ) {
847
+ break ;
848
+ }
849
+ }
850
+ this . generateMessage ( RULE_STRENGTH , name ) ;
851
+ return ;
852
+ }
853
+
801
854
case RULE_ZIP :
802
855
{
803
856
if ( ! ruleValue ) {
@@ -857,6 +910,8 @@ function _defineProperty(obj, key, value) { if (key in obj) { Object.definePrope
857
910
} ,
858
911
859
912
renderErrors : function renderErrors ( ) {
913
+ var _this4 = this ;
914
+
860
915
this . clearErrors ( ) ;
861
916
this . unlockForm ( ) ;
862
917
@@ -897,6 +952,26 @@ function _defineProperty(obj, key, value) { if (key in obj) { Object.definePrope
897
952
_item . parentNode . insertBefore ( div , _item . nextSibling ) ;
898
953
}
899
954
}
955
+
956
+ if ( ! this . tooltipSelectorWrap . length ) {
957
+ return ;
958
+ }
959
+
960
+ this . state . tooltipsTimer = setTimeout ( function ( ) {
961
+ _this4 . hideTooltips ( ) ;
962
+ } , this . tooltipFadeOutTime ) ;
963
+ } ,
964
+
965
+ hideTooltips : function hideTooltips ( ) {
966
+ var _this5 = this ;
967
+
968
+ var $elemsErrorLabel = document . querySelectorAll ( '.js-validate-error-label' ) ;
969
+
970
+ $elemsErrorLabel . forEach ( function ( item ) {
971
+ item . classList . add ( _this5 . tooltipFadeOutClass ) ;
972
+ } ) ;
973
+
974
+ this . state . tooltipsTimer = null ;
900
975
} ,
901
976
902
977
lockForm : function lockForm ( ) {
0 commit comments