diff --git a/specifyweb/frontend/js_src/lib/components/FormCells/index.tsx b/specifyweb/frontend/js_src/lib/components/FormCells/index.tsx index b228daff8ed..6c2d0a394fc 100644 --- a/specifyweb/frontend/js_src/lib/components/FormCells/index.tsx +++ b/specifyweb/frontend/js_src/lib/components/FormCells/index.tsx @@ -221,7 +221,7 @@ const cellRenderers: { const watchFields = f.unique( filterArray( definitions.map(({ condition }) => - condition?.type === 'Value' ? condition?.field[0].name : undefined + condition?.type !== 'Always' ? condition?.field[0].name : undefined ) ) ); diff --git a/specifyweb/frontend/js_src/lib/components/FormEditor/viewSpec.ts b/specifyweb/frontend/js_src/lib/components/FormEditor/viewSpec.ts index 55d488e32af..2ef06897aa3 100644 --- a/specifyweb/frontend/js_src/lib/components/FormEditor/viewSpec.ts +++ b/specifyweb/frontend/js_src/lib/components/FormEditor/viewSpec.ts @@ -141,8 +141,15 @@ const rowsSpec = (table: SpecifyTable | undefined) => if (isAlways) return { type: 'Always' } as const; const [rawField, ...condition] = rawCondition.split('='); const field = syncers.field(table?.name).serializer(rawField); + const isEmpty = condition.at(-1) === 'EMPTY'; return field === undefined ? undefined + : isEmpty + ? ({ + type: 'Empty', + field, + value: '', + } as const) : ({ type: 'Value', field, @@ -154,8 +161,11 @@ const rowsSpec = (table: SpecifyTable | undefined) => if (props.type === 'Always') return localized('always'); const { field, value } = props; const joined = syncers.field(table?.name).deserializer(field); + const isEmpty = props.type === 'Empty'; return joined === undefined || joined.length === 0 ? undefined + : isEmpty + ? localized(`${joined}=EMPTY`) : localized(`${joined}=${value}`); } ) diff --git a/specifyweb/frontend/js_src/lib/components/FormParse/__tests__/index.test.ts b/specifyweb/frontend/js_src/lib/components/FormParse/__tests__/index.test.ts index 570600e4100..1faf1845055 100644 --- a/specifyweb/frontend/js_src/lib/components/FormParse/__tests__/index.test.ts +++ b/specifyweb/frontend/js_src/lib/components/FormParse/__tests__/index.test.ts @@ -191,6 +191,11 @@ const conditionalTinyFormView = strictParseXml( + + + + + ` ); const parsedConditionalTinyView: ParsedFormDefinition = { @@ -444,7 +449,7 @@ describe('parseFormDefinition', () => { formDefinition.map(({ condition, ...rest }) => ({ ...rest, condition: - condition === undefined || condition.type !== 'Value' + condition === undefined || condition.type === 'Always' ? condition : { ...condition, @@ -465,6 +470,14 @@ describe('parseFormDefinition', () => { }, definition: parsedConditionalTinyView, }, + { + condition: { + type: 'Empty', + field: ['cataloger'], + value: '', + }, + definition: parsedConditionalTinyView, + }, ]); }); }); diff --git a/specifyweb/frontend/js_src/lib/components/FormParse/index.ts b/specifyweb/frontend/js_src/lib/components/FormParse/index.ts index bfad30f0e1e..ac3bde3b61f 100644 --- a/specifyweb/frontend/js_src/lib/components/FormParse/index.ts +++ b/specifyweb/frontend/js_src/lib/components/FormParse/index.ts @@ -465,6 +465,13 @@ export type FormCondition = readonly value: string; } > + | State< + 'Empty', + { + readonly field: RA; + readonly value: ''; + } + > | State<'Always'> | undefined; @@ -508,14 +515,23 @@ export async function parseFormDefinition( const value = condition.slice(1).join('='); const parsedField = table.getFields(condition[0]); if (Array.isArray(parsedField)) { - return { - condition: { - type: 'Value', - field: parsedField, - value, - }, - definition, - } as const; + return value === 'EMPTY' + ? ({ + condition: { + type: 'Empty', + field: parsedField, + value: '', + }, + definition, + } as const) + : ({ + condition: { + type: 'Value', + field: parsedField, + value, + }, + definition, + } as const); } }