From ac492b4e2ce4ca294fb14b5a6873e7f83418cf73 Mon Sep 17 00:00:00 2001 From: Lizandro Guarnizo <77708265+lizandrogd@users.noreply.github.com> Date: Thu, 9 Jul 2026 14:55:17 -0500 Subject: [PATCH] fix: apply conditional field visibility in editable form (ver_formulario_enviado) Add data-campo-id attributes to all editable field wrappers and separators, then run iniciarCondiciones-equivalent JS on page load so conditional sections (e.g. Tipo de dolor when Dolores is checked) appear/disappear without needing to close and reopen the modal. Co-Authored-By: Claude Sonnet 4.6 --- ver_formulario_enviado.php | 65 ++++++++++++++++++++++++++++++++++---- 1 file changed, 58 insertions(+), 7 deletions(-) diff --git a/ver_formulario_enviado.php b/ver_formulario_enviado.php index 6fc74b0..b82ee0c 100644 --- a/ver_formulario_enviado.php +++ b/ver_formulario_enviado.php @@ -650,7 +650,7 @@ function esc2(mixed $v): string { $_saltarSeccion = false; } if ($_saltarSeccion) continue; ?> -
+
-
+
-
+
@@ -842,7 +842,7 @@ function esc2(mixed $v): string { if ($tipo === 'radio'): $opts = $campo['opciones'] ?? $campo['options'] ?? []; ?> -
+
@@ -859,7 +859,7 @@ function esc2(mixed $v): string { $checkedArr = is_array($prefill) ? $prefill : (is_string($prefill) && $prefill !== '' ? (json_decode($prefill, true) ?: [$prefill]) : []); ?> -
+
@@ -876,7 +876,7 @@ function esc2(mixed $v): string { if ($tipo === 'select'): $opts = $campo['opciones'] ?? $campo['options'] ?? []; ?> -
+
@@ -1627,6 +1627,57 @@ const topaz = (() => { })(); +// ── Condiciones de visibilidad (secciones condicionales) ────── +(function() { + var esquema = ; + var secciones = [], secActual = null; + esquema.forEach(function(c) { + if (c.tipo === 'separador') { + secActual = { sepId: c.id, condicion: c.condicion || null, elemIds: [] }; + secciones.push(secActual); + } else if (secActual) { + secActual.elemIds.push(c.id); + } + }); + var condicionales = secciones.filter(function(s) { return s.condicion; }); + if (!condicionales.length) return; + + function evaluar() { + condicionales.forEach(function(sec) { + var cond = sec.condicion; + var valoresCond = cond.valores ? cond.valores : (cond.valor ? [cond.valor] : []); + var ctrl = document.querySelector('[data-campo-id="' + cond.campo_id + '"]'); + if (!ctrl) return; + var activo = false; + var checks = ctrl.querySelectorAll('input[type="checkbox"]'); + if (checks.length) { + checks.forEach(function(cb) { if (valoresCond.includes(cb.value) && cb.checked) activo = true; }); + } else { + var radio = ctrl.querySelector('input[type="radio"]:checked'); + var sel = ctrl.querySelector('select'); + var v = radio ? radio.value : (sel ? sel.value : ''); + activo = valoresCond.includes(v); + } + var ids = [sec.sepId].concat(sec.elemIds); + ids.forEach(function(id) { + var el = document.querySelector('[data-campo-id="' + id + '"]'); + if (!el) return; + el.style.transition = 'opacity .2s, max-height .3s'; + el.style.maxHeight = activo ? '2000px' : '0'; + el.style.opacity = activo ? '1' : '0'; + el.style.overflow = activo ? '' : 'hidden'; + el.style.pointerEvents = activo ? '' : 'none'; + }); + }); + } + + var ctrlIds = [...new Set(condicionales.map(function(s) { return s.condicion.campo_id; }))]; + ctrlIds.forEach(function(cid) { + var el = document.querySelector('[data-campo-id="' + cid + '"]'); + if (el) el.addEventListener('change', evaluar); + }); + evaluar(); +})(); // ── Auto-save borrador (campo a campo, sin firma) ───────────── (function() { var _t;