reblocks icon indicating copy to clipboard operation
reblocks copied to clipboard

fix: serialize forms submitted by <button>

Open hraban opened this issue 1 year ago • 6 comments

A more modern approach using form submit event’s ‘submitter’ property.

https://caniuse.com/mdn-api_submitevent_submitter

Also requires changes to reblocks-ui

hraban avatar Jul 04 '24 19:07 hraban

Why this is better approach (aside that it is more "modern")?

svetlyak40wt avatar Jul 05 '24 10:07 svetlyak40wt

Also, I see at https://caniuse.com/mdn-api_submitevent_submitter that Internet Explorer does not support "submitter" even in the latest version. This could be a problem for some users.

svetlyak40wt avatar Jul 05 '24 10:07 svetlyak40wt

Why this is better approach (aside that it is more "modern")?

This patch a fix for forms containing <button>s. Those aren't caught by the old code.

Another thing this catches is non-click submission events, e.g. if you're in an field and press Enter, a default submit button is selected and used as the submission. A regular post form catches that.

Also, I see at https://caniuse.com/mdn-api_submitevent_submitter that Internet Explorer does not support "submitter" even in the latest version. This could be a problem for some users.

Internet explorer is obsolete and unsupported even by MS now I think. https://en.wikipedia.org/wiki/Internet_Explorer says development stopped in 2016 and all support ended 2022.

hraban avatar Jul 05 '24 13:07 hraban

Aha! I'll have to play with this first. Thank you for the PR.

svetlyak40wt avatar Jul 05 '24 13:07 svetlyak40wt

@hraban I've build this simple demo using the latest version of Reblocks and Reblocks-ui:

https://gist.github.com/svetlyak40wt/47df0712195ca49c1ae96c62294c4bd3

And both button and input :type button works perfectly with keyboard events.

Could you please update this example to make it possible to reproduce the problem which can be solved by "submitter"?

svetlyak40wt avatar Jul 07 '24 08:07 svetlyak40wt

The point is getting the value of the button. Try this one https://github.com/40ants/reblocks-websocket/issues/4 but substitute the <input name="x" value="y" type="submit"> with <button name="x" value="y">y</button>.

hraban avatar Jul 07 '24 16:07 hraban

@hraban sorry for a long delay with replies, I'm having some troubles with health and have to solve them asap.

However today I've tested your changes from this PR and from your PR to rebocks-ui, on my example form and noticed that form is submitted as usual POST request with full page reload instead of Ajax request:

Screenshot 2024-07-28 at 00 27 32

Do you have any ideas how to fix this behaviour?

svetlyak40wt avatar Jul 27 '24 21:07 svetlyak40wt

@svetlyak40wt if you also use reblocks-ui you need this PR : https://github.com/40ants/reblocks-ui/pull/10

hraban avatar Jul 28 '24 16:07 hraban

Good luck with your health btw!! Best wishes.

hraban avatar Jul 28 '24 16:07 hraban

@svetlyak40wt if you also use reblocks-ui you need this PR : 40ants/reblocks-ui#10

Hmm, I've used both PRs. However now after the full application restart it works as Ajax requests. Probably some code was in conflict when I've switched branches and did quickload in my previous attempt.

svetlyak40wt avatar Jul 28 '24 17:07 svetlyak40wt

Merged as part of the https://github.com/40ants/reblocks/pull/62

svetlyak40wt avatar Jul 28 '24 18:07 svetlyak40wt