auto-form icon indicating copy to clipboard operation
auto-form copied to clipboard

Issue / feature: defaultValues

Open moltco opened this issue 1 year ago • 0 comments

I believe the order of preference for defaultValue should be changed so the inputProps have priority over Zod schema.

The rationale behind this is that Zod schema is 'fixed' and then the inputProps are used to 'override' form attributes.

Following this logic, I specify 'defaultValue' in inputProps this should be taken as preferred html value attribute. At the moment, auto-forms tries to find default from the Zod schema, if fails then it looks at input Props.

A typical use case could be that I have one static Zod schema for the form which I may decide to fill in with 'default' data if I am creating a new record, or if editing existing record - I would normally provide existing data to be edited (not the 'default' data).

Email.defaultValue("[email protected]") -> good for creating a new user Email.defaultValue("[email protected]") -> when editing existing record of [email protected]

If you are happy to reverse the logic here, I would be happy to create a PR with the changes.

moltco avatar Sep 09 '24 11:09 moltco