1+ const MAX_QUATITY = 5 ;
2+ const MAX_QUANTITY_SIMBOL = 140 ;
3+
14const uploadForm = document . querySelector ( '.img-upload__form' ) ;
25const hashtagsInput = uploadForm . querySelector ( '.text__hashtags' ) ;
36const descriptionInput = uploadForm . querySelector ( '.text__description' ) ;
47
5- const MAX_QUATITY = 5 ;
6- const MAX_QUANTITY_SIMBOL = 140 ;
7-
88let errorMessage = '' ;
99
1010const pristine = new Pristine ( uploadForm , {
@@ -17,20 +17,20 @@ const validateForm = () => pristine.validate();
1717
1818const checkRules = [
1919 {
20- check : ( inputArray ) => inputArray . some ( ( element ) => ! / ^ # [ a - z а - я ё 1 - 9 ] { 1 , 19 } $ / i. test ( element ) ) ,
20+ check : ( inputsArray ) => inputsArray . some ( ( element ) => ! / ^ # [ a - z а - я ё 1 - 9 ] { 1 , 19 } $ / i. test ( element ) ) ,
2121 error : 'Не допустимые символы!'
2222 } ,
2323 {
24- check : ( inputArray ) => inputArray . length > MAX_QUATITY ,
24+ check : ( inputsArray ) => inputsArray . length > MAX_QUATITY ,
2525 error : `Не более ${ MAX_QUATITY } хэштегов!`
2626 } ,
2727 {
28- check : ( inputArray ) => inputArray . some ( ( element , num , Array ) => Array . includes ( element , num + 1 ) ) ,
28+ check : ( inputsArray ) => inputsArray . some ( ( element , num , elementsArray ) => elementsArray . includes ( element , num + 1 ) ) ,
2929 error : 'Хэштэги не должны повторяться!'
3030 } ,
3131] ;
3232
33- const validHashtags = ( value ) => {
33+ const validateHashtags = ( value ) => {
3434 const inputText = value . toLowerCase ( ) . trim ( ) ;
3535 const inputArray = inputText . split ( ' ' ) ;
3636
@@ -51,11 +51,11 @@ const validHashtags = (value) => {
5151 return checks ;
5252} ;
5353
54- const validDescription = ( value ) => {
55- const inputCommentArray = value ;
56- inputCommentArray . split ( ' ' ) ;
54+ const validateDescription = ( value ) => {
55+ const inputCommentsArray = value ;
56+ inputCommentsArray . split ( ' ' ) ;
5757
58- const isInvalid = inputCommentArray . length > MAX_QUANTITY_SIMBOL ;
58+ const isInvalid = inputCommentsArray . length > MAX_QUANTITY_SIMBOL ;
5959
6060 if ( isInvalid ) {
6161 errorMessage = `Не более ${ MAX_QUANTITY_SIMBOL } символов!` ;
@@ -65,8 +65,8 @@ const validDescription = (value) => {
6565} ;
6666
6767const initValidation = ( ) => {
68- pristine . addValidator ( hashtagsInput , validHashtags , ( ) => errorMessage ) ;
69- pristine . addValidator ( descriptionInput , validDescription , ( ) => errorMessage ) ;
68+ pristine . addValidator ( hashtagsInput , validateHashtags , ( ) => errorMessage ) ;
69+ pristine . addValidator ( descriptionInput , validateDescription , ( ) => errorMessage ) ;
7070} ;
7171
7272export { initValidation , validateForm } ;
0 commit comments