You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Area: InstrumentsInstrument authoring API, bundling, runtime, rendering, measures and the built-in libraryArea: Webapps/web (clinician-facing React SPA)Difficulty: HighMore than a day, or touches several workspacesEnhancementType: an improvement to an existing feature, including performanceNeeds DecisionWell-defined, but blocked on a maintainer decision about direction or designPriority: MediumReal value; schedule normallyUpstreamThe fix belongs in a @douglasneuroinformatics/* package or a third-party dependency
Still open on main (d86740e), and nothing upstream supports it yet. libui's Form renders no required marker, in the installed 6.16.1 or in the latest 6.18.0. BaseField in libui-form-types has only description, disabled, kind and label, in the installed 1.4.0 and in the latest 1.5.0. Neither repo has an issue for it.
The flag is no longer stored
When this was filed, isRequired?: boolean was on the base field type (packages/common/src/instruments/interfaces/form/form-fields.types.ts:28 at 5752c8c). No published version of libui-form-types has ever had the key. runtime-core's FieldMixin does not add it, and c73d4fa (2024-09-06) replaced isRequired: z.boolean().optional() with disabled in packages/schemas. Whether a field is required now lives only in validationSchema.
Four isRequired keys are left over, and nothing reads them:
packages/instrument-guidelines/AGENTS.md:885. This is the published form example, and it sets isRequired: true on a dynamic field.
The schema alone cannot drive the marker
To make a field required only under some condition, authors make the key .optional() and enforce it in a superRefine. Examples: Happiness reasonNotSatisfied (:169, :172), playground Multilingual-Form-With-Dynamic-Field (:78, :80) and the guidelines example (AGENTS.md:937, :939). In apps/web/src/components/StartSessionForm/StartSessionForm.tsx, subjectDateOfBirth and subjectSex are static fields (:162, :167) that are optional in the shape (:225-241) and required only for PERSONAL_INFO (:291). A marker read from the shape shows all of these as optional.
libui cannot read the schema at all. It types it as ZodTypeLike (Form.tsx:63), which exposes only safeParseAsync. ODC can, because runtime-core types validationSchema as z3.ZodType | z4.ZodType (packages/runtime-core/src/types/instrument.base.ts:161).
Recommendation: an explicit flag, with a default derived from the schema
Upstream. Add isRequired?: boolean to BaseField. The flag only controls display; validation stays in the schema. Existing keys and instruments copied from the guidelines then work without edits.
libui should render the marker once, in a shared FieldGroup label. Today 16 field files each render their own <Label>.
Set aria-required on controls whose role supports it. slider does not, so the label also needs screen-reader text. Add the legend string to libui's en/es/fr translations.
Do not use the required attribute. libui's <form> (Form.tsx:192) has no noValidate, so the browser would block onSubmit and the localized zod errors would never show.
ODC types. Bump both catalog: entries. runtime-core picks up the key through FieldMixin, and translateScalarField already copies it with ...field.
Also add the key to $$FormInstrumentBaseField (packages/schemas/src/instrument/instrument.form.ts:21-27). Its satisfies does not catch a missing optional key. Without the key, $AnyInstrument.parseAsync strips the flag from static fields wherever validate is on: the playground preview (apps/playground/src/preview/PreviewApp.tsx:67) and apps/web in dev (apps/web/src/hooks/useInstrument.ts:20). The outreach JSON Schema is also generated from it.
This ships in a runtime/v1 release, because runtime/v1 re-bundles runtime-core.
Derived default. Add a helper to packages/instrument-utils and apply it in FormContent.
For each field the author left unset, set isRequired to !shape[key].safeParse(undefined).success. That covers .optional(), .default() and .partial() in both zod majors.
Walk both flat and grouped content. Wrap dynamic render the same way translateFormFields does (translate.ts:184-195).
Call safeParse only when the flag is unset. It throws on an async refinement, which libui accepts because it validates with safeParseAsync. Decide up front whether that case renders unmarked or fails loudly.
upload.ts already finds the object shape in four places (:448-457, :483-501, :810-820, :835-847), including the zod 3 ZodEffects unwrap. Put one shared lookup next to the helper instead of writing a fifth.
Content. Set isRequired: true in the render of Happiness reasonNotSatisfied and of playground favoriteColor. Document the flag in the guidelines (that means a release of @opendatacapture/instrument-guidelines) and in docs/en/5-reference/5.0-form-instrument.md.
Land this after #1825, which edits the same instrument and instrument-completion.spec.ts.
Tests
The helper's own test in packages/instrument-utils/src/__tests__/: a required key, an .optional() key, a .default() key, a zod 3 superRefine object, a zod 4 object and a dynamic field. Also check that the author's flag overrides the derived value.
packages/react-core/src/components/FormContent/__tests__/FormContent.test.tsx: a required field shows the marker and an optional one does not.
packages/instrument-utils/src/__tests__/translate.test.ts: the flag survives translation of static and dynamic fields.
packages/schemas/src/instrument/__tests__/instrument.form.test.ts: the parsed output keeps the flag.
testing/src/specs/instrument-completion.spec.ts: in the Happiness Questionnaire, the sliders and the overall question are marked and "causes" is not. After answering "No", the reason field is marked.
Open questions
Asterisk on required fields, or "(optional)" on optional ones? I lean towards the asterisk. When an override is missing, an unmarked required field misleads less than a required field labelled "(optional)".
Derive a default at all, or rely on the explicit flag only?
Should the 13 <Form> sites in apps/web get markers too? They get no derived default from FormContent. In StartSessionForm, subjectSex and subjectDateOfBirth would also have to become dynamic fields that depend on subjectIdentificationMethod.
Handle record-array fieldsets and number-record rows now, or only top-level keys?
Triage note written with Claude Code. Code references point at main @ d86740e.
Area: InstrumentsInstrument authoring API, bundling, runtime, rendering, measures and the built-in libraryArea: Webapps/web (clinician-facing React SPA)Difficulty: HighMore than a day, or touches several workspacesEnhancementType: an improvement to an existing feature, including performanceNeeds DecisionWell-defined, but blocked on a maintainer decision about direction or designPriority: MediumReal value; schedule normallyUpstreamThe fix belongs in a @douglasneuroinformatics/* package or a third-party dependency
Activity
[-]Indicate required vs optional fields[/-][+][Enhancement]: Indicate required vs optional fields[/+]#390 adds asterisk to required fields for subject
#390 adds asterisk to required fields for subject
joshunrau commentedon Mar 5, 2024
Make as required in JSLibs please @david-roper
[-][Enhancement]: Indicate required vs optional fields[/-][+]Indicate required vs optional fields[/+]joshunrau commentedon Oct 26, 2026
Still open on
main(d86740e), and nothing upstream supports it yet. libui'sFormrenders no required marker, in the installed 6.16.1 or in the latest 6.18.0.BaseFieldinlibui-form-typeshas onlydescription,disabled,kindandlabel, in the installed 1.4.0 and in the latest 1.5.0. Neither repo has an issue for it.The flag is no longer stored
When this was filed,
isRequired?: booleanwas on the base field type (packages/common/src/instruments/interfaces/form/form-fields.types.ts:28at 5752c8c). No published version oflibui-form-typeshas ever had the key. runtime-core'sFieldMixindoes not add it, and c73d4fa (2024-09-06) replacedisRequired: z.boolean().optional()withdisabledinpackages/schemas. Whether a field is required now lives only invalidationSchema.Four
isRequiredkeys are left over, and nothing reads them:packages/instrument-library/src/forms/DNP_HAPPINESS_QUESTIONNAIRE/index.ts:75and:93. fix: resolve 26 low-difficulty issues, one commit each #1825 (for Happiness Questionnaire shows the missing-reason error above the Submit button instead of under the reason field #1674) removes:75, which contradicted the schema.apps/playground/src/instruments/examples/form/Form-With-Groups/index.tsx:101.packages/instrument-guidelines/AGENTS.md:885. This is the published form example, and it setsisRequired: trueon a dynamic field.The schema alone cannot drive the marker
To make a field required only under some condition, authors make the key
.optional()and enforce it in asuperRefine. Examples: HappinessreasonNotSatisfied(:169,:172), playgroundMultilingual-Form-With-Dynamic-Field(:78,:80) and the guidelines example (AGENTS.md:937,:939). Inapps/web/src/components/StartSessionForm/StartSessionForm.tsx,subjectDateOfBirthandsubjectSexare static fields (:162,:167) that are optional in the shape (:225-241) and required only forPERSONAL_INFO(:291). A marker read from the shape shows all of these as optional.libui cannot read the schema at all. It types it as
ZodTypeLike(Form.tsx:63), which exposes onlysafeParseAsync. ODC can, because runtime-core typesvalidationSchemaasz3.ZodType | z4.ZodType(packages/runtime-core/src/types/instrument.base.ts:161).Recommendation: an explicit flag, with a default derived from the schema
isRequired?: booleantoBaseField. The flag only controls display; validation stays in the schema. Existing keys and instruments copied from the guidelines then work without edits.FieldGrouplabel. Today 16 field files each render their own<Label>.aria-requiredon controls whose role supports it.sliderdoes not, so the label also needs screen-reader text. Add the legend string to libui's en/es/fr translations.requiredattribute. libui's<form>(Form.tsx:192) has nonoValidate, so the browser would blockonSubmitand the localized zod errors would never show.catalog:entries. runtime-core picks up the key throughFieldMixin, andtranslateScalarFieldalready copies it with...field.$$FormInstrumentBaseField(packages/schemas/src/instrument/instrument.form.ts:21-27). Itssatisfiesdoes not catch a missing optional key. Without the key,$AnyInstrument.parseAsyncstrips the flag from static fields wherevervalidateis on: the playground preview (apps/playground/src/preview/PreviewApp.tsx:67) andapps/webin dev (apps/web/src/hooks/useInstrument.ts:20). The outreach JSON Schema is also generated from it.runtime/v1release, becauseruntime/v1re-bundles runtime-core.packages/instrument-utilsand apply it inFormContent.isRequiredto!shape[key].safeParse(undefined).success. That covers.optional(),.default()and.partial()in both zod majors.content. Wrap dynamicrenderthe same waytranslateFormFieldsdoes (translate.ts:184-195).safeParseonly when the flag is unset. It throws on an async refinement, which libui accepts because it validates withsafeParseAsync. Decide up front whether that case renders unmarked or fails loudly.upload.tsalready finds the object shape in four places (:448-457,:483-501,:810-820,:835-847), including the zod 3ZodEffectsunwrap. Put one shared lookup next to the helper instead of writing a fifth.isRequired: truein therenderof HappinessreasonNotSatisfiedand of playgroundfavoriteColor. Document the flag in the guidelines (that means a release of@opendatacapture/instrument-guidelines) and indocs/en/5-reference/5.0-form-instrument.md.Land this after #1825, which edits the same instrument and
instrument-completion.spec.ts.Tests
packages/instrument-utils/src/__tests__/: a required key, an.optional()key, a.default()key, a zod 3superRefineobject, a zod 4 object and a dynamic field. Also check that the author's flag overrides the derived value.packages/react-core/src/components/FormContent/__tests__/FormContent.test.tsx: a required field shows the marker and an optional one does not.packages/instrument-utils/src/__tests__/translate.test.ts: the flag survives translation of static and dynamic fields.packages/schemas/src/instrument/__tests__/instrument.form.test.ts: the parsed output keeps the flag.testing/src/specs/instrument-completion.spec.ts: in the Happiness Questionnaire, the sliders and the overall question are marked and "causes" is not. After answering "No", the reason field is marked.Open questions
<Form>sites inapps/webget markers too? They get no derived default fromFormContent. InStartSessionForm,subjectSexandsubjectDateOfBirthwould also have to become dynamic fields that depend onsubjectIdentificationMethod.Triage note written with Claude Code. Code references point at
main@d86740e.