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

Add formRef prop support

Open vbhanuc87 opened this issue 6 months ago • 2 comments

Hey there,

This is an awesome library and simplified my work to create forms way faster, eliminating all the boilerplate code required.

However, a quick question or may be something I am missing from docs, not sure.

Is it possible to submit the form from an external button ?

My use case:

  • I have a zod schema and attached to AutoForm with the ZodProvider
  • The form is rendering inside a Dialog and Dialog is having the Save and Cancel buttons
  • I want to submit the form from the Save button in Dialog.
  • Been trying from couple of hours, but not able to trigger the submit from outside, the problem is with validations not firing, as per the Zod schema validation. Let me know if I'm missing something or if there's an alternate / better way to achieve what I'm trying to do, or let me know if it doesn't work out this way.

Is withSubmit the only way to trigger field validations ?

vbhanuc87 avatar Jun 22 '25 23:06 vbhanuc87

I think it would be good to add support for a formRef prop to allow doing this easily.

For now you can try using the "onFormInit" prop to get access to the react-hook-form instance (https://autoform.vantezzen.io/docs/react/api#onforminit-form-forminstance--void) - but I don't know if there is some way to submit the form with that

vantezzen avatar Jun 23 '25 07:06 vantezzen

Place the buttons inside the AutoForm as children with correct type like submit

https://codesandbox.io/p/github/adityacodepublic/project2/main?import=true

adityacodepublic avatar Jun 27 '25 12:06 adityacodepublic