Repository navigation
Description
In the Happiness Questionnaire, the error for a missing dissatisfaction reason is not attached to the reason field. A subject who answers "No" to "Overall, would you say you are satisfied with your life?" and leaves "Why do you feel dissatisfied with your life?" empty cannot submit, and sees "This field is required / Ce champ est obligatoire". The superRefine that raises this error calls ctx.addIssue without a path, so the issue's path is empty. libui's Form (handleError in src/components/Form/Form.tsx) puts every issue with an empty path in rootErrors, which it renders above the Submit button, and the reason field gets no error styling. At that point two empty fields are on screen: the reason and the optional "causes" listbox. The message says "This field" without naming either, so the subject has to guess which one to fill. The dynamic field also returns isRequired: false, which nothing reads and which contradicts the schema.
Where
packages/instrument-library/src/forms/DNP_HAPPINESS_QUESTIONNAIRE/index.ts:172-179:
.superRefine((arg, ctx) => {
if (!arg.isSatisfiedOverall && !arg.reasonNotSatisfied) {
ctx.addIssue({
code: 'custom',
message: 'This field is required / Ce champ est obligatoire'
});
}
})Reproduce
- Administer the Happiness Questionnaire.
- Set both sliders and answer "No" to the overall question.
- Leave the reason empty and click Submit.
Actual: "This field is required / Ce champ est obligatoire" appears above the Submit button, and the reason field shows no error.
Expected: the error appears under "Why do you feel dissatisfied with your life?", like every other required-field error.
Tests
packages/instrument-library/src/__tests__/DNP_HAPPINESS_QUESTIONNAIRE.test.ts: it('should attach the missing-reason error to reasonNotSatisfied, so the form shows it under that field'). Assert that result.error?.issues[0]?.path equals ['reasonNotSatisfied'].
testing/src/specs/instrument-completion.spec.ts: test('should show the missing-reason error under the reason field when a dissatisfied subject leaves it empty'). Answer "No", leave the reason empty, submit, and expect the error message inside the reasonNotSatisfied field rather than above the Submit button.
Suggested fix
Add path: ['reasonNotSatisfied'] to the addIssue call. Remove the unread isRequired: false from the reasonNotSatisfied field.
Activity
fix(instrument-library): show the happiness missing-reason error unde…