Skip to content

Commit 533bb93

Browse files
committed
[PRAC/cont] Correct "common" validation function
Transition/adding "universal" classes, working them out. Worth noting: - upcoming solution/moving to a "common" modal window. core: B-3 / JS-BL
1 parent 985ba65 commit 533bb93

File tree

1 file changed

+16
-14
lines changed
  • core-courses/3-js-basic-level/practicum-js-basic-level/sb-crm-client/js

1 file changed

+16
-14
lines changed

core-courses/3-js-basic-level/practicum-js-basic-level/sb-crm-client/js/index.js

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -286,7 +286,8 @@
286286
);
287287
addModalBodySurnameInput.classList.add(
288288
'modal__add-body-input',
289-
'add-surname-input',
289+
'modal-main-input',
290+
'modal-surname-input',
290291
'add-modal-input',
291292
'form-control'
292293
);
@@ -310,7 +311,8 @@
310311
);
311312
addModalBodyNameInput.classList.add(
312313
'modal__add-body-input',
313-
'add-name-input',
314+
'modal-main-input',
315+
'modal-name-input',
314316
'add-modal-input',
315317
'form-control'
316318
);
@@ -334,7 +336,8 @@
334336
);
335337
addModalBodyPatronymicInput.classList.add(
336338
'modal__add-body-input',
337-
'add-patronymic-input',
339+
'modal-main-input',
340+
'modal-patronymic-input',
338341
'add-modal-input',
339342
'form-control'
340343
);
@@ -493,7 +496,7 @@
493496
.classList.toggle('show-search-input');
494497
});
495498

496-
// ** организация "ОБЩЕЙ" логики для валидации полей ввода/инпутов (согласно передаваемых параметров)
499+
// ** организация "общей/универсальной" логики для валидации полей ввода/инпутов (согласно передаваемых параметров)
497500
function addInputsValidation(inputs, options) {
498501
inputs.forEach((input) =>
499502
input.addEventListener('input', (event) => {
@@ -519,7 +522,7 @@
519522
// проверки для полей ввода/инпутов из "динамической" строки контактов (согласно type="" значений)
520523
if (options.dynamicContactValidation) {
521524
const hiddenInput = targetParentNode.querySelector(
522-
'.modal__add-body-add-hidden-input'
525+
'.modal-hidden-input'
523526
);
524527

525528
if (hiddenInput) {
@@ -982,11 +985,11 @@
982985
);
983986
}
984987

988+
// дополнительная/опциональная проверка для инпутов, обработка дефисов
985989
if (options.singleHyphen) {
986-
// дополнительная проверка для двух инпутов (дефисы недопустимы)
987990
if (
988-
target.classList.contains('add-name-input') ||
989-
target.classList.contains('add-patronymic-input')
991+
target.classList.contains('modal-name-input') ||
992+
target.classList.contains('modal-patronymic-input')
990993
) {
991994
if (/-/.test(target.value)) {
992995
errors.push('Дефисы НЕдопустимы!');
@@ -1003,9 +1006,9 @@
10031006
}
10041007
}
10051008

1006-
// дополнительная проверка для "modal__add-body-input" (пробелы недопустимы)
1009+
// дополнительная/опциональная проверка для инпутов, обработка пробелов
10071010
if (
1008-
target.classList.contains('modal__add-body-input') &&
1011+
target.classList.contains('modal-main-input') &&
10091012
/\s/.test(target.value)
10101013
) {
10111014
errors.push('Пробелы НЕдопустимы!');
@@ -1037,9 +1040,7 @@
10371040
});
10381041

10391042
// добавление валидации для ввода данных/в модальном окне (при добавлении нового/клиента)
1040-
const allAddModalFormInputs = document.querySelectorAll(
1041-
'.modal__add-body-input'
1042-
);
1043+
const allAddModalFormInputs = document.querySelectorAll('.modal-main-input');
10431044
addInputsValidation(allAddModalFormInputs, {
10441045
allowOnlyRussian: true,
10451046
singleHyphen: true,
@@ -1171,7 +1172,8 @@
11711172
'add-modal-extra-contact-item'
11721173
);
11731174
addModalContactHiddenInput.classList.add(
1174-
'modal__add-body-add-hidden-input'
1175+
'modal__add-body-add-hidden-input',
1176+
'modal-hidden-input'
11751177
);
11761178
addModalContactInput.classList.add(
11771179
'modal__add-body-add-contact-input',

0 commit comments

Comments
 (0)