fix: checkbox _c8j2g16 usa name[] en HTML, no name exacto
El campo tipo examen es checkbox → HTML renderiza name="_c8j2g16[]". Todos los querySelector y el listener comparaban name="_c8j2g16" exacto → nunca matcheaban → visibilidad de secciones y panel de config nunca se activaban. Añade _mpGetExamName()/_mpSetExamChecked() que aceptan ambas variantes y los usa en todos los puntos de uso. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Sonnet 4.6
parent
182dc01a77
commit
65b18facdb
@@ -1334,11 +1334,22 @@ function _mpApplyExamVisibility(selectedExam) {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Helper: leer examen seleccionado (funciona para radio name=_c8j2g16 y checkbox name=_c8j2g16[])
|
||||||
|
function _mpGetExamName() {
|
||||||
|
var el = document.querySelector('[name="_c8j2g16"]:checked,[name="_c8j2g16[]"]:checked');
|
||||||
|
return el ? el.value : null;
|
||||||
|
}
|
||||||
|
function _mpSetExamChecked(name) {
|
||||||
|
var esc = name.replace(/"/g, '\\"');
|
||||||
|
var el = document.querySelector('[name="_c8j2g16"][value="' + esc + '"],[name="_c8j2g16[]"][value="' + esc + '"]');
|
||||||
|
if (el) el.checked = true;
|
||||||
|
}
|
||||||
|
|
||||||
// Escuchar selección de tipo de examen
|
// Escuchar selección de tipo de examen
|
||||||
document.addEventListener('change', function(e) {
|
document.addEventListener('change', function(e) {
|
||||||
var el = e.target;
|
var el = e.target;
|
||||||
if (el.name !== '_c8j2g16') return;
|
if (el.name.replace(/\[\]$/, '') !== '_c8j2g16') return;
|
||||||
var examName = (el.type === 'checkbox' && !el.checked) ? null : el.value;
|
var examName = _mpGetExamName();
|
||||||
_mpApplyExamVisibility(examName);
|
_mpApplyExamVisibility(examName);
|
||||||
// Panel de configuración solo en modo turnero y si aún no está configurado
|
// Panel de configuración solo en modo turnero y si aún no está configurado
|
||||||
if (!_mpModoTurnero || _mpTomasConfig !== null || !examName) return;
|
if (!_mpModoTurnero || _mpTomasConfig !== null || !examName) return;
|
||||||
@@ -1349,8 +1360,7 @@ document.addEventListener('change', function(e) {
|
|||||||
|
|
||||||
// Al cargar: aplicar visibilidad (sin examen = ocultar todo)
|
// Al cargar: aplicar visibilidad (sin examen = ocultar todo)
|
||||||
document.addEventListener('DOMContentLoaded', function() {
|
document.addEventListener('DOMContentLoaded', function() {
|
||||||
var radio = document.querySelector('[name="_c8j2g16"]:checked');
|
var examName = _mpGetExamName();
|
||||||
var examName = radio ? radio.value : null;
|
|
||||||
// Restaurar selección de examen tras el reload del panel de config
|
// Restaurar selección de examen tras el reload del panel de config
|
||||||
if (!examName) {
|
if (!examName) {
|
||||||
try {
|
try {
|
||||||
@@ -1358,8 +1368,7 @@ document.addEventListener('DOMContentLoaded', function() {
|
|||||||
if (saved) {
|
if (saved) {
|
||||||
sessionStorage.removeItem('_mpExamRestore');
|
sessionStorage.removeItem('_mpExamRestore');
|
||||||
examName = saved;
|
examName = saved;
|
||||||
var el = document.querySelector('[name="_c8j2g16"][value="' + saved.replace(/"/g, '\\"') + '"]');
|
_mpSetExamChecked(saved);
|
||||||
if (el) el.checked = true;
|
|
||||||
}
|
}
|
||||||
} catch(e) {}
|
} catch(e) {}
|
||||||
}
|
}
|
||||||
@@ -1371,7 +1380,7 @@ document.addEventListener('DOMContentLoaded', function() {
|
|||||||
|
|
||||||
// Botón "Usar todas"
|
// Botón "Usar todas"
|
||||||
document.getElementById('mp-cfg-todas').addEventListener('click', function() {
|
document.getElementById('mp-cfg-todas').addEventListener('click', function() {
|
||||||
var examName = (document.querySelector('[name="_c8j2g16"]:checked') || {}).value || '';
|
var examName = _mpGetExamName() || '';
|
||||||
var cfg = {};
|
var cfg = {};
|
||||||
document.querySelectorAll('.mp-cfg-chk').forEach(function(chk) {
|
document.querySelectorAll('.mp-cfg-chk').forEach(function(chk) {
|
||||||
if (!cfg[chk.dataset.group]) cfg[chk.dataset.group] = [];
|
if (!cfg[chk.dataset.group]) cfg[chk.dataset.group] = [];
|
||||||
@@ -1387,7 +1396,7 @@ document.getElementById('mp-cfg-todas').addEventListener('click', function() {
|
|||||||
|
|
||||||
// Botón "Iniciar protocolo"
|
// Botón "Iniciar protocolo"
|
||||||
document.getElementById('mp-cfg-iniciar').addEventListener('click', function() {
|
document.getElementById('mp-cfg-iniciar').addEventListener('click', function() {
|
||||||
var examName = (document.querySelector('[name="_c8j2g16"]:checked') || {}).value || '';
|
var examName = _mpGetExamName() || '';
|
||||||
var byGroup = {};
|
var byGroup = {};
|
||||||
document.querySelectorAll('.mp-cfg-chk').forEach(function(chk) {
|
document.querySelectorAll('.mp-cfg-chk').forEach(function(chk) {
|
||||||
if (!byGroup[chk.dataset.group]) byGroup[chk.dataset.group] = [];
|
if (!byGroup[chk.dataset.group]) byGroup[chk.dataset.group] = [];
|
||||||
|
|||||||
Reference in New Issue
Block a user