andyrichardson / fielder

A field-first form library for React and React Native
https://fielder.andyrichardson.dev
MIT License
195 stars 10 forks source link

handleSubmit is not firing #322

Closed waylio closed 2 years ago

waylio commented 2 years ago

Hey,

Basically, I have 2 problems:

  1. Forms submits anywhere I press enter. I've made a workaround using the following code

    <form onKeyDown={(e) => {
        if (e.keyCode == 13) {
            e.preventDefault();
            return false;
        }
    }}>
    >

    I wonder if this is the right way to do it using fielder.

  2. handleSubmit is not firing despite that isSubmitted has been set to true.

 const { handleSubmit, hasSubmitted, isValidating } = useSubmit(async (values) => {
        console.log('submit')
 });

<form>
        <button onClick={handleSubmit} type="button">Create Product {hasSubmitted ? 'true' : 'false'}</button>
</form 

I set type="button" cause the default value makes the form submit without firing handleSubmit too.

Best

andyrichardson commented 2 years ago

Hey @waylio thanks for filing the report!

Forms submits anywhere I press enter. I've made a workaround using the following code

Thanks for sharing this - your workaround seems like a good alternative if you find that you want to use the handleSubmit function to the onSubmit handler in the form :+1:

handleSubmit is not firing despite that isSubmitted has been set to true.

This doesn't seem quite right! I'm going to guess that your component isn't inside of a FielderProvider (see here).

If that isn't the case, check out this working example and see if there are any obvious omissions. Or feel free to post your own sandbox example with a reproduction.

andyrichardson commented 2 years ago

Going to go ahead and close this. Drop a comment if you're still needing some help :+1: