document.addEventListener('DOMContentLoaded', function () { const NUM = v => String(v||'').replace(/\s+/g,'').replace(',', '.').trim(); function bindDimSet(form, selName, otherName, wrapSelector, hiddenSelector){ const sel = form.querySelector(`select[name="${selName}"]`); const other = form.querySelector(`input[name="${otherName}"]`); const wrap = form.querySelector(wrapSelector); const hidden = form.querySelector(hiddenSelector); if(!sel || !other || !wrap || !hidden) return; const isOther = () => { const v = (sel.value||'').toLowerCase().trim(); const t = sel.options[sel.selectedIndex]?.text?.toLowerCase() || ''; return v === 'other' || /rozwiązanie\s*niestandardowe/.test(t); }; function sync(){ if(isOther()){ wrap.style.display = ''; other.required = true; hidden.value = NUM(other.value); }else{ wrap.style.display = 'none'; other.required = false; other.value = ''; hidden.value = NUM(sel.value); } } sel.addEventListener('change', sync); other.addEventListener('input', sync); sync(); } function bindForm(form){ if (form.dataset.ppBound) return; form.dataset.ppBound = '1'; // LP (bez prefixu) bindDimSet(form,'width_sel', 'width_other', '.pp-width-other', 'input[name="your-szerokosc-2"]'); bindDimSet(form,'length_sel', 'length_other', '.pp-length-other', 'input[name="your-dlugosc-2"]'); bindDimSet(form,'height_sel', 'height_other', '.pp-height-other', 'input[name="your-wysokosc-2"]'); // SIDEBAR (prefix sb_) bindDimSet(form,'sb_width_sel', 'sb_width_other', '.pp-width-other', '#sb-your-szerokosc-2'); bindDimSet(form,'sb_length_sel', 'sb_length_other', '.pp-length-other', '#sb-your-dlugosc-2'); bindDimSet(form,'sb_height_sel', 'sb_height_other', '.pp-height-other', '#sb-your-wysokosc-2'); // walidacja finalnych hiddenów form.addEventListener('wpcf7beforesubmit', function(e){ const finals = [ form.querySelector('input[name="your-szerokosc-2"]') || form.querySelector('#sb-your-szerokosc-2'), form.querySelector('input[name="your-dlugosc-2"]') || form.querySelector('#sb-your-dlugosc-2'), form.querySelector('input[name="your-wysokosc-2"]') || form.querySelector('#sb-your-wysokosc-2') ].filter(Boolean); ['width_sel','length_sel','height_sel','sb_width_sel','sb_length_sel','sb_height_sel'].forEach(n=>{ const el = form.querySelector(`select[name="${n}"]`); if(el) el.dispatchEvent(new Event('change')); }); const bad = finals.filter(el => !/^(\d+(\.\d+)?)$/.test((el.value||'').trim())); if (bad.length){ e.preventDefault(); alert('Podaj poprawne wymiary (np. 20 lub 23.5).'); } }); } document.querySelectorAll('.wpcf7 form').forEach(bindForm); const obs = new MutationObserver(() => { document.querySelectorAll('.wpcf7 form').forEach(bindForm); }); obs.observe(document.body, {childList:true, subtree:true}); });
Czego szukasz
Lista artykułów:
Czy na halę namiotową potrzebne jest pozwolenie – to jedno z najczęściej zadawanych pytań przez inwestorów planujących budowę lub montaż obiektu tymczasowego. Hala namiotowa to […]

Napisz do nas
Odpowiemy i przygotujemy dla Ciebie szczegółową wycenę w ciągu max. 3 dni roboczych.