-
-
Notifications
You must be signed in to change notification settings - Fork 241
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
Submit Form Normally When Pressing Enter Button #224
Comments
It's very difficult to understand what you're asking for. First result for me with https://lmgtfy.app/?q=submit+form+on+enter is https://stackoverflow.com/questions/477691/submitting-a-form-by-pressing-enter-without-a-submit-button Here's a short piece of code that does it. I did not test this. document.querySelectorAll("input").forEach(el => {
el.addEventListener("keydown", ev => {
if (ev.key === "Enter") {
el.form.submit()
}
})
}) Or did I misunderstand your question? Are you asking how to make the form submit when the user hits the Enter key while using keyboard navigation on the autoComplete list? If so, then you just do it in In any case this is not an issue, it's a question. There's a new github feature called Discussions, look for the tab at the top along with the others. |
Hey @folknor Autocomplete.js prevents the form from submitting normally by pressing Enter key, what i am looking for is ability to submit the query string normally to a server something like search.php and show results there. In some cases if we want to display all matched results for the query the better option would be to show all results in a dedicated page, so that’s why i am looking for an option to submit the form by pressing Enter key. Sorry, My bad, I should have used discussions for this. Exact functionality can be found here at this website |
Ah, I see. Yes, that is because autoComplete.js does
function interceptEnterKey(e) {
if (e.keyCode === 13 && iWantToRedirectToSearchPHP) {
return true
}
return false
}
let orig = myinput.addEventListener
myinput.addEventListener = function () {
let f = arguments[1]
if (arguments[0] === "keydown") {
arguments[1] = function (e) {
if (interceptEnterKey(e)) {
return
}
f(e)
}
}
orig.apply(this, arguments)
} Please note that the above is pseudocode I wrote dry, without testing, without validating syntax, and without really knowing if it works. I think the concept should work. The reason you need to do this is because autoComplete.js removes and re-adds its event listener every time the result list opens.
new autoComplete({
resultsList: {
navigation: function() {}
}
}); |
Thank you @folknor , The first option concept and code got me going in the right direction. |
I'm facing this issue with version I think having the autocomplete library prevent the default behaviour of
|
Hi @TarekRaafat,
Huge Thanks For This Library.
Is there an option to submit the form normally when pressing "Enter" button? Played for some time with the trigger config but no use.
My use case is to show autocomplete results for input as well as the ability to submit the form on pressing Enter button, more like Google search.
The text was updated successfully, but these errors were encountered: