Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

submit form programmatically #3023

Closed
galr52 opened this issue Aug 17, 2022 · 4 comments
Closed

submit form programmatically #3023

galr52 opened this issue Aug 17, 2022 · 4 comments

Comments

@galr52
Copy link

galr52 commented Aug 17, 2022

Hey,

I am trying to submit a form programmatically.
i have read the docs:
https://react-jsonschema-form.readthedocs.io/en/latest/advanced-customization/internals/#submit-form-programmatically

but my form wont submitting:

https://stackblitz.com/edit/react-ygpqie?file=src/App.js

any idea what am i doing wrong?

@rjsf/core: 4.2.3
react: 18.2.0

thanks in advance,

@github-actions github-actions bot added the needs triage Initial label given, to be assigned correct labels and assigned label Aug 17, 2022
@heath-freenome
Copy link
Member

Can you try the v5 beta and see if it works now? There was an issue that hopefully was fixed

@heath-freenome heath-freenome removed the needs triage Initial label given, to be assigned correct labels and assigned label Sep 7, 2022
@galr52
Copy link
Author

galr52 commented Sep 8, 2022

Can you try the v5 beta and see if it works now? There was an issue that hopefully was fixed

yes, it is working on v5 beta

also as @WillowP suggested, a fix for v4 can be done by make the button a submit button and just set the form attribute.

const ExampleB = () => {
  const onSubmit = ({ formData }) => {
    console.log('Data submitted: ', formData)
  };
  const schema = {
    type: 'string',
  };

  return (
    <div style={{ border: '1px solid black', padding: '4px' }}>
      <h3>Example B</h3>
      <Form
        id="my-form"
        schema={schema}
        onSubmit={onSubmit}
      >
        <></>
      </Form>
      <button type="submit" form="my-form">Submit</button>
    </div>
  );
};

https://stackblitz.com/edit/react-1yurkc?file=src%2FApp.js

@heath-freenome
Copy link
Member

Closing as this works in the v5 beta

@MaximeCrp
Copy link

Do you know if this is going to be released in a patch for v4?

@nickgros nickgros mentioned this issue Jan 8, 2024
4 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants