Cannot validate complete nested object
Describe the bug and the expected behavior
I'm trying to use form.validate.getButtonProps to validate a complete fieldset, i.e. a field that consists only of nested fields.
The validation will produce the errors of the subfields, but it since for the fieldset field no value is submitted, it will never land in the list of validatedFields, and thus not have any errors assigned.
I would have expected that validating a nested object field causes all subfields of this field to be validated, and have their errors reported.
Suggestion When sending a validate intent, always validate all fields for which the field name is a prefix.
Or, make it configurable with a recursive flag on the ValidationIntent payload
Conform version
v1.2.2
Steps to Reproduce the Bug or Issue
Here is a sandbox that demonstrates the problem: https://codesandbox.io/p/devbox/smoosh-frost-gf79qd?workspaceId=1702db6b-2042-4a59-957b-ee67bb3c5948
I've added two buttons to the ToDo List example, a "Validate Task" button, which triggers the described behaviour (of not doing anything, basically). For comparison, there is also a "Validate Task Content" button, which works as expected.
Steps
- Click on Todo list
- Click on Add task
- Click on Validate Task
- I would have expected the task content to become red
-
Click on Validate Task Content
- This works, but it validates only one leaf field
But there is no way to validate an entire field with subfields.
What browsers are you seeing the problem on?
No response
Screenshots or Videos
No response
Additional context
No response
I'm cross-linking this StackBlitz example from https://github.com/edmundhung/conform/issues/830#issuecomment-2743719920 because it helps greatly to illustrate the problem.
I have created a StackBlitz based on the multi-validate PR (#878) that demonstrates the problem, based on your suggestion to collect the field names from the Form element:
https://stackblitz.com/edit/uzog2zz5?file=src%2Ftodos.tsx
- Open the Todos List example
- Add a Task
- Click the Clear button to enable the Validate button[^1]
- Click Validate button
- Note that only the Content field error shows up in the Task's error list
- Click the Save button at the bottom of the Form
- Note that now also the Error for the Tags array shows up in the Task's error list
[^1]: perhaps I did something wrong there, but I guess at the time of first rendering, there are no fields in the Form with the tasks' name prefix, which would be another drawback of your suggestion.