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
Maybe I missed it, but I'm not seeing any guidance in the docs on how to actually respond to form submission, gather field values and send them to an API or otherwise utilize them.
It seems like the user is expected to attach a submit handler to the <form> or <button type="submit"> elements, and then read the form state from const formState = useForm(), i.e. formState.fields.foo.value, etc. Is that right?
While it makes sense from a "thinking with hooks" perspective, this is a significant departure from what users are used to with incumbent solutions like Formik, which all revolve around providing an explicit onSubmit handler which receives the gathered values directly.
The Getting Started docs probably need a full explanation of how to actually handle form submission and extract values.
If there's no more convenient way to pull the entire set of field values than referencing formState.fields.foo.value on every one of them, I'd also suggest we figure out something more convenient. Ideally I'd want a plain structured object of field values.
Perhaps an onSubmit handler function could also be passed to useForm() for the sake of being a bit more intuitive for newcomers (there's danger in opening multiple pathways to functionality, of course)?
Finally, because this is a field-centric library, for TypeScript users the documentation should probably indicate clearly that you must pass a field schema type to useForm<FieldSchema>() for field values to be typed and accessible in the form state. While that's intuitive, I've seen this problem trip up other new TypeScript users who aren't used to conventions yet.
Let me know how I can assist on any of these! I'm happy to contribute.
The text was updated successfully, but these errors were encountered:
Hey @a-type thanks for creating this issue! Full breakdown below.
Why there's no 'handleSubmit'
this is a significant departure from what users are used to with incumbent solutions like Formik, which all revolve around providing an explicit onSubmit handler which receives the gathered values directly.
Fielder is a huge departure from the approach of libraries such as Formik, and this is intentional.
Because of how the field-level implementation works, we don't make any assumption about a "final desired state" - hence why validation isn't declared upfront and neither is the submit handler.
This means working with more dynamic forms where branching is involved is much easer.
This could be improved
That being said, I can completely see where the confusion is coming from and this is definitely something that I'm going to have to add to the docs!
For the time being, you'll want to declare your submit/progression handler in the component where the progressive action (i.e. submit button click) is declared.
Maybe I missed it, but I'm not seeing any guidance in the docs on how to actually respond to form submission, gather field values and send them to an API or otherwise utilize them.
It seems like the user is expected to attach a submit handler to the
<form>
or<button type="submit">
elements, and then read the form state fromconst formState = useForm()
, i.e.formState.fields.foo.value
, etc. Is that right?While it makes sense from a "thinking with hooks" perspective, this is a significant departure from what users are used to with incumbent solutions like Formik, which all revolve around providing an explicit
onSubmit
handler which receives the gathered values directly.The Getting Started docs probably need a full explanation of how to actually handle form submission and extract values.
If there's no more convenient way to pull the entire set of field values than referencing
formState.fields.foo.value
on every one of them, I'd also suggest we figure out something more convenient. Ideally I'd want a plain structured object of field values.Perhaps an
onSubmit
handler function could also be passed touseForm()
for the sake of being a bit more intuitive for newcomers (there's danger in opening multiple pathways to functionality, of course)?Finally, because this is a field-centric library, for TypeScript users the documentation should probably indicate clearly that you must pass a field schema type to
useForm<FieldSchema>()
for field values to be typed and accessible in the form state. While that's intuitive, I've seen this problem trip up other new TypeScript users who aren't used to conventions yet.Let me know how I can assist on any of these! I'm happy to contribute.
The text was updated successfully, but these errors were encountered: