Exclude field from onSubmit and validators
Can I have a form field defined in defaultValues and use it in my code, but exclude it from the form onSubmit callback and exclude it from the validators? e.g:
I don't want
partId to be part of value: deliveryNoteFormData variable and exclude it in the validators property too8 Replies
rare-sapphire•2mo ago
can the user change the partId?
or is it static data coming in from somewhere?
fair-roseOP•2mo ago
Hmmmm indirectly yes, I want to have a "picker" combobox field which sets both
partId and partReferenceId (they are meaningful I swear đŸ˜…). I want to validate and submit partReferenceId only.rare-sapphire•5w ago
Okay, so
partId and partReferenceId are both changeable by the user, but you don't need the partId in any Dtos or the like.
What is the partId used for, then? A lookup for visual display?fair-roseOP•5w ago
My code needs it for some queries and filtering đŸ¤“
rare-sapphire•5w ago
hmmm ... so I assume when you said
"... and exclude it in the
validators property too"
you want it to be hidden from, say, a zod schema?
There isn't a feature to remove fields like this from validation / submission yet, so I was trying to assess when / how the partId is neededfair-roseOP•5w ago
Yess
Ohhh okay, no worries
I am currently adding @ts-ignore to avoid lint errors and unpacking the onSubmit value to discard the field, but this is a bad solution
rare-sapphire•5w ago
@ts-expect-error is better, but that aside, do you have an example of the field values and the zod schema that are type complaining?fair-roseOP•5w ago
I have but it is not minimal đŸ˜…
My field, where I set both values whenever partReferenceId changes. The picker supplies both values