How to modify formData on turbo:submit-start
See original GitHub issueI want to modify any form of my page when they are submitted. I tried to add some data to the form modifying the formData of the formSubmission object:
document.addEventListener('turbo:submit-start', function (event) {
event.detail.formSubmission.formData.append('input_name', 'example_value');
});
but looks like the fetchRequest object that has the formData that will be submitted is already constructed, so changes in formSubmission object will not change the fetchRequest object. Am I right? How can I achieve to modify the form data via turbo event?
Thanks.
Issue Analytics
- State:
- Created 2 years ago
- Comments:5
Top Results From Across the Web
How to modify formData on turbo:submit-start #303 - bytemeta
I want to modify any form of my page when they are submitted. I tried to add some data to the form modifying...
Read more >generic approach to add controllers from FormType classes ...
My root form has controller unload that will ask user to confirm turbo:visit if FormData has been changed. And it works but the...
Read more >Form validation in Rails - DEV Community
We'll first set up our User model, then UsersController , then we'll move ... async validate(event) { const formData = await event.detail.
Read more >RubyGems - turbo-rails - Versions diffs - 1.0.0 → 1.0.1 - Diffend
Load your application's JavaScript bundle inside the <head> element instead. <script> elements in <body> are evaluated with each page change. @@ -21,5 + ......
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
So finally I figure out how to make it works. Thanks @michelson for the idea of request.js. At the end, I have modified the fetchRequest body object of the formSubmission object. Just in case it helps someone in the future, here is how I did it:
Thanks again!
For anybody else coming to this, I was looking for a way to sync some fields on submit. Hooking into the
turbo:submit-start
seemed like the ideal approach, but it seems like that was too late in the process.Instead, I just hooked into the normal form submit event and synced the hidden fields there. Then, when
turbo:submit-start
is fired, the form data is already there.