feat(ar1): show_if nel wizard + dedup dettaglio Quadro C/D
- evaluator show_if (== \x27x\x27, == true, != true): Quadro E mostra le sezioni 1a-2b solo con motivo B; campi condizionali coerenti col seed - nested_full visibile e validato solo se la condizione vale: LR gia indicato tra i TE del Quadro B non richiede il dettaglio aggiuntivo
This commit is contained in:
@@ -55,6 +55,19 @@ const Ar1Wizard = () => {
|
||||
return false;
|
||||
};
|
||||
|
||||
// show_if formati seed: "campo == 'VALORE'", "campo == true", "campo != true"
|
||||
const evalShowIf = (expr, quadroData) => {
|
||||
if (!expr) return true;
|
||||
const m = String(expr).match(/^\s*(\w+)\s*(==|!=)\s*(?:'(.*)'|(true|false))\s*$/);
|
||||
if (!m) return true; // formato ignoto: non nascondere mai per errore
|
||||
const raw = (quadroData || {})[m[1]];
|
||||
const val = raw && typeof raw === 'object' && 'value' in raw ? raw.value : raw;
|
||||
const target = m[4] !== undefined ? (m[4] === 'true') : m[3];
|
||||
const eq = m[4] !== undefined ? (!!val === target) : (String(val ?? '') === target);
|
||||
return m[2] === '==' ? eq : !eq;
|
||||
};
|
||||
const isFieldVisible = (field, quadroData) => evalShowIf(field.show_if, quadroData);
|
||||
|
||||
const validateQuadro = (quadro, data) => {
|
||||
const errs = [];
|
||||
const d = data || {};
|
||||
@@ -78,8 +91,14 @@ const Ar1Wizard = () => {
|
||||
if (sl.required && isEmptyVal(d[sl.id])) errs.push(`Quadro ${quadro.id}: allegato obbligatorio — ${sl.label}`);
|
||||
});
|
||||
(quadro.fields || []).forEach(f => {
|
||||
if (f.required && !f.show_if && isEmptyVal(d[f.id])) errs.push(`Quadro ${quadro.id}: ${f.label}`);
|
||||
if (f.required && isFieldVisible(f, d) && isEmptyVal(d[f.id])) errs.push(`Quadro ${quadro.id}: ${f.label}`);
|
||||
});
|
||||
if (quadro.nested_full && evalShowIf(quadro.nested_full.show_if, d)) {
|
||||
const nd = d.nested || {};
|
||||
(quadro.nested_full.fields || []).forEach(f => {
|
||||
if (f.required && isFieldVisible(f, nd) && isEmptyVal(nd[f.id])) errs.push(`Quadro ${quadro.id} (dettaglio): ${f.label}`);
|
||||
});
|
||||
}
|
||||
return errs;
|
||||
};
|
||||
|
||||
@@ -416,8 +435,8 @@ const Ar1Wizard = () => {
|
||||
<div>
|
||||
<h3>{quadro.title}</h3>
|
||||
{quadro.description && <p style={{ color: '#666' }}>{quadro.description}</p>}
|
||||
{(quadro.fields || []).map(field => renderField(field, q[field.id], (fid, val) => handleFieldChange(quadro.id, fid, val), `q-${quadro.id}`))}
|
||||
{quadro.nested_full && (
|
||||
{(quadro.fields || []).filter(field => isFieldVisible(field, q)).map(field => renderField(field, q[field.id], (fid, val) => handleFieldChange(quadro.id, fid, val), `q-${quadro.id}`))}
|
||||
{quadro.nested_full && evalShowIf(quadro.nested_full.show_if, q) && (
|
||||
<div style={{ marginTop: 16, padding: 12, background: '#f5f5f5', borderRadius: 4 }}>
|
||||
<h4 style={{ marginTop: 0 }}>{__('Dettaglio aggiuntivo', 'gepafin')}</h4>
|
||||
{(quadro.nested_full.fields || []).map(field => renderField(
|
||||
|
||||
Reference in New Issue
Block a user