react-jsonschema-form icon indicating copy to clipboard operation
react-jsonschema-form copied to clipboard

Programmatic submit does not work properly in Firefox

Open nickgros opened this issue 2 years ago • 9 comments

Prerequisites

What theme are you using?

core

Version

5.0.0-beta6

Current Behavior

When using Firefox programmatic submit ends up embedding a copy of the entire page into the rendered form

image

Expected Behavior

No response

Steps To Reproduce

No response

Environment

- OS:
- Node:
- npm:

Anything else?

No response

nickgros avatar Sep 16 '22 16:09 nickgros

@jacqueswho Do you have time to take a look at this?

heath-freenome avatar Sep 21 '22 06:09 heath-freenome

ill take a look

jacqueswho avatar Sep 21 '22 06:09 jacqueswho

I also faced same issue. Want programmatically submit as we ll as validating forms also

saswat3115 avatar Dec 21 '22 14:12 saswat3115

Workaround: it seems instead of calling ref.current.submit() as in the docs, you can do ref.current.formElement.current.requestSubmit()

nickgros avatar Jun 01 '23 16:06 nickgros

Workaround: it seems instead of calling ref.current.submit() as in the docs, you can do ref.current.formElement.current.requestSubmit()

Can confirm, this works. Might want to add this to the docs (temporarily).

I looked a bit further into this. And I think (not tested) it has something to do with the dispatched event not being the same event as the actual formSubmitEvent. So when adding e.g. e.preventDefault() in the onSubmitHandler it is trying to stop the formSubmit event and not the custom dispatched event.

I don't have the time to test this, but one could try to add a customEvent.preventDefault() closely after the dispatch and see if it still occurs.

emielvanseveren avatar Jun 22 '23 10:06 emielvanseveren

I looked a bit further into this. And I think (not tested) it has something to do with the dispatched event not being the same event as the actual formSubmitEvent. So when adding e.g. e.preventDefault() in the onSubmitHandler it is trying to stop the formSubmit event and not the custom dispatched event.

Also ran into this issue - though in Chrome - where it was causing the onSubmit function to be called twice. Fortunately, the ref.current.formElement.current.requestSubmit() workaround helps 👍 .

snlamm avatar Jun 26 '23 19:06 snlamm

I can confirm this does not work on Safari. I can see the issue in the playground also.

It seems

requestSubmit

is not supported in Safari at all. So the above workaround also is not working!

hirenr avatar Dec 26 '23 10:12 hirenr

With the merge of #4150, is this issue now closed?

jeremy-marcus avatar Jun 03 '24 13:06 jeremy-marcus

@jeremy-marcus It most likely is. @nickgros would you be willing to confirm this and close it?

heath-freenome avatar Jun 06 '24 00:06 heath-freenome