document.addEventListener("DOMContentLoaded", function () { const input = document.getElementById("txt11458"); const errorSpan = document.getElementById("elemIDerr11458"); const sendBtn = document.getElementById("finishForm"); const inputContainer = document.querySelector('[fieldid="MisparPniaIroor"]'); if (!input || !errorSpan || !sendBtn || !inputContainer) { console.warn("אלמנטים לא נמצאו – ודא שהדף נטען במלואו"); return; } // בדיקה אם האלמנט גלוי בדף function isElementVisible(el) { return el.offsetParent !== null; } function validateMisparPnia() { // אם השדה לא גלוי – נחשיב אותו כלא נדרש if (!isElementVisible(inputContainer)) { errorSpan.textContent = ""; return true; } const value = input.value.trim(); const isValid = /^\d{8}$/.test(value); if (!isValid) { errorSpan.textContent = "נא להזין בדיוק 8 ספרות (ללא אותיות)"; errorSpan.style.color = "red"; return false; } else { errorSpan.textContent = ""; return true; } } input.addEventListener("blur", validateMisparPnia); const originalOnClick = function () { try { fixTextAreas(); validator('1', ''); } catch (err) { console.warn("שגיאה בהרצת הפונקציה המקורית", err); } }; sendBtn.onclick = function () { if (validateMisparPnia()) { originalOnClick(); } else { input.focus(); } }; console.log("קובץ הולידציה נטען ומזהה הופעה מותנית של שדה ✅"); });