-
Notifications
You must be signed in to change notification settings - Fork 64
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
Prevent double submit prevents button value from being submitted #688
Comments
@MarkPaxton what is your use case for needing the the |
I have a form, which I want to add (or remove) lines. In order to do this the form will be submitted to the server and re-rendered with an extra line (or line removed). This I am proposing to do with a submit button indicating to the server which operation on the form is required (submit data, add line, remove line x). Therefore there will be several buttons on the form initiating the submit and it would be necessary to identify which was clicked, using name and value. If there is no name on the button, the value is can't be submitted as it has no identifier. |
I suspect the problem you are seeing is because |
@MarkPaxton In |
That is for if you want to submit your form with jquery, which I don't, but have no choice over. Js form submission is baked in to application.js |
It's probably going to be easier to work around it to be honest. I wouldn't have enabled this as a default behaviour but now it's there and built into all existing services I don't think it would be a good idea to turn it off again. There's a case for adding a disable attribute but then most other workarounds will be as easy without that too. |
That is a valid point we should be explicitly adding this functionality, not implicitly adding it to all form submit buttons. I do however feel the root issue here is relying on 2 submit buttons and branching in the controller based on the values of these submit buttons. I would revisit this. |
Does this mean that forms with multiple buttons will never be supported? We're creating an admin interface for internal staff and think we have also encountered this issue. In our instance the secondary buttons can be links. instead, but not Mark's. Form submissions should be prevented using conditional event cancellation, then there would be no need to submit the form with JavaScript, and the server will receive consistent requests regardless of whether JavaScript was available. |
assets-frontend/assets/javascripts/modules/preventDoubleSubmit.js
Line 4 in 3610585
The js event handler attached at preventDoubleSubmit.js prevents the button data from being submitted in the request.
In a form where the submit button is assigned a value
With JS disabled the form is submitted with "submit=Tea" as part of the form data.
With JS enabled the form is submitted without this value.
With js enabled execute:
Then click the button. The button data is then submitted within the form data.
The text was updated successfully, but these errors were encountered: