0

For some reason I can't find any similar problems online. The form is structured like this answer suggests- Getting iPhone GO button to submit form

Here is the form-

<form id="searchForm" method="get" action="">
 <input type="search" placeholder="Search.." name="query" id="searchTerm" aria-label="Search" list="searchList" autocomplete="off" spellcheck="true">
 <datalist id="searchList">
 <option>Detroit Lions</option>
 <option>Detroit Pistons</option>
 <option>Detroit Red Wings</option>
 <option>Detroit Tigers</option>
 </datalist>
 <button type="submit" name="search" ></button>
</form>

When any option is selected and the input is updated with the new value, the iPhone keyboard submit does not work unless there is an additional key press before pressing the submit.

I was updating the datalist with javascript and thought that may be the issue but after hardcoding the above values the problem persists. Strangely sometimes the iPhone keyboard submit would work but I could not tell what the difference was.

I have tried changing autocomplete to on. I have tried putting an extra space after the option value. I have some ideas with javascript but would like suggestions before I spend too much time on the wrong approach.

iPhone version 12.4.1 and 14.4.1 and 14.7.1

*update- I tried implementing a javascript solution without success. The search/go submit only works if the user presses an additional key after selecting from the datalist. Using javascript to trigger a key press did not work. Iphone go/search works on other sites with datalists. Not sure what to try next.

asked Sep 3, 2021 at 0:56

1 Answer 1

1

Hey, below solution worked for me to make work the search button on the phone keyboard:

 <form id="searchForm" method="get" action="">
 <input type="search" placeholder="Search.." name="query" id="searchTerm" aria-label="Search" list="searchList" autocomplete="off" spellcheck="true">
 <datalist id="searchList">
 <option>Detroit Lions</option>
 <option>Detroit Pistons</option>
 <option>Detroit Red Wings</option>
 <option>Detroit Tigers</option>
 </datalist>
 <button type="submit" name="search" id="myBtn" ></button>
 </form>
.
.
.
<script>
var input = document.getElementById("searchTerm");
input.addEventListener("keyup", function(event) {
 if (event.keyCode === 13) {
 event.preventDefault();
 document.getElementById("myBtn").click();
 }
});
</script>

I added a js script at the end to trigger button click on enter and my search button on Iphone keyboard worked with the selected option on datalist.

answered Feb 16, 2022 at 10:04
Sign up to request clarification or add additional context in comments.

1 Comment

Thank you for your answer, I used the same solution but never got around to updating my question. I was hoping for a non js solution because it should work without it.

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.