<div class="popup_calc" data-modal="true">
<div class="popup_dialog">
<div class="popup_calc_content text-center">
<button type="button" class="popup_calc_close"><strong>×</strong></button>
<h2>Калькулятор</h2>
<h3>Выберите форму балкона <br>и укажите размеры</h3>
<div class="balcon_icons">
<span class="balcon_icons_img do_image_more">
<img src="assets/img/modal_calc/balkon/ba_01.png" alt="Тип1"></span>
<span class="balcon_icons_img">
<img src="assets/img/modal_calc/balkon/ba_02.png" alt="Тип2"></span>
<span class="balcon_icons_img">
<img src="assets/img/modal_calc/balkon/ba_03.png" alt="Тип3"></span>
<span class="balcon_icons_img">
<img src="assets/img/modal_calc/balkon/ba_04.png" alt="Тип4"></span>
</div>
<div class="big_img text-center">
<img src="assets/img/modal_calc/balkon/type1.png" alt="Тип1">
<img src="assets/img/modal_calc/balkon/type2.png" alt="Тип2">
<img src="assets/img/modal_calc/balkon/type3.png" alt="Тип3">
<img src="assets/img/modal_calc/balkon/type4.png" alt="Тип4">
</div>
<input class="form-control" id="width" type="text" placeholder="Ширина" required>
<label for="width">мм</label>
<div class="multiplication"><strong>×</strong></div>
<input class="form-control" id="height" type="text" placeholder="Высота" required>
<label for="height">мм</label>
<button class="button popup_calc_button">Далее</button>
</div>
</div>
</div>
function validateInputs(modal) {
const btn = modal.querySelector('.button');
const inputs = modal.querySelectorAll('input[type="text"]');
const checkboxes = modal.querySelectorAll('input[type="checkbox"]');
const validateInputs = Array.from(inputs).some(input => input.value.trim() === '');
const validateCheckboxes = Array.from(checkboxes).every(checkbox => checkbox.checked === false);
if (validateInputs || validateCheckboxes) {
btn.disabled = true;
} else {
btn.disabled = false;
}
}
export default validateInputs;
import checkNumInputs from "./checkNumInputs";
import validateInputs from "./validateInputs";
function changeModalState(state) {
const windowForm = document.querySelectorAll('.balcon_icons_img');
const windowWidth = document.querySelectorAll('#width');
const windowHeight = document.querySelectorAll('#height');
const windowType = document.querySelectorAll('#view_type');
const windowProfile = document.querySelectorAll('.checkbox');
checkNumInputs('#width');
checkNumInputs('#height');
function bindActionToElem(action, elem, prop) {
elem.forEach((item, index) => {
item.addEventListener(action, () => {
const modal = item.closest('[data-modal="true"]');
console.log(modal);
switch (item.nodeName) {
case 'SPAN' : {
state[prop] = index
break;
}
case 'INPUT' : {
if (item.getAttribute('type') === 'checkbox') {
index === 0 ? state[prop] = 'Холодное' : state[prop] = 'Теплое';
elem.forEach((box, jindex) => {
box.checked = false;
if (index === jindex) {
box.checked = true;
}
});
} else {
state[prop] = item.value;
}
break;
}
case 'SELECT' : {
state[prop] = item.value;
break;
}
}
validateInputs(modal);
console.log(state);
});
});
}
bindActionToElem('click', windowForm, 'form');
bindActionToElem('input', windowWidth, 'width');
bindActionToElem('input', windowHeight, 'height');
bindActionToElem('change', windowType, 'type');
bindActionToElem('change', windowProfile, 'profile');
}
export default changeModalState;
every
для пустого массива?||
?