-
-
Notifications
You must be signed in to change notification settings - Fork 333
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
Form submit causes undesired request / page reload #1632
Comments
You could always use JavaScript to listen for enter being pressed and prevent it from submitting the form? I'd imagine you'd only want this within a input field, since textarea could have legit new lines put in for paragraphing... Quick search on Stackoverflow yields the below: |
The FUI logic to fetch (also) the enter key can basically disabled by For your usecase you can simply add See your adjusted jsfiddle here https://jsfiddle.net/lubber/he8szqno/9/ |
Hi, thank you for your quick support. Unfortunately, it's not enough, because it just adds another "onkeypress" handler. The others execute nevertheless. However, based on your idea, I tried adding Now I see the following issues:
I patched that by removing all "submit" events on jexcel focus (caching the original ones), and re-attaching it on blur... but that's really dirty... |
This actually did help. Neither the form is submitted, nor the validation is triggered... It did neither require Now it is just restricted usability... |
Thank you guys, this did the trick. Not perfect, but I can live with it! |
You could continue to use enter, but call your Ajax function when enter is captured/prevented for submitting the form. I'm unsure if |
True... |
Closing for now, because i don't think we should hardcode any kind of "onsubmit=return false" logic. Workarounds are given above. |
Bug Report
I'm building a single page (JavaScript) application and I have an issue with the form submission. Basically, I never want the page to reload. Everything should be handled with JavaScript/Ajax in the background. It seems Fomantic is automatically attaching "submit" events to the form under certain circumstances. If triggered, the form executes a standard POST/GET request, causing the page to reload.
Now I've figured out two circumstances, under which the standard "submit" is triggered:
Well, I can easily remove the submit class from the button, however, I haven't figured out a way to get rid of the >enter< key event (or better - redirect it to my custom AJAX submit function). So, my application behaves correctly, if the submit button is clicked, but not if >enter< is pressed.
Expected result
Same behaviour, no matter whether the user clicks the submit button or presses the >enter< key.
Actual result
The >enter< submit event leads to an undesired behaviour, sending a POST/GET request, when an AJAX requet is desired... and causing an undesired page (re)load.
Testcase
https://jsfiddle.net/y4nc2ob6/
Here is a fiddle. On click nothing happens, because the onclick events do not contain code. However, if you fill in some string and hit >enter<, you can observe a GET request being sent out. You can see it in the developer tool bar... or fiddle will show a 404 error. The page should be reloaded too, but I guess it happens too quickly with the short fiddle HTML code.
Version
I tried with different Fomantic and Jquery versions, including the latest ones.
The text was updated successfully, but these errors were encountered: