FireFox datalist does not open until double click - html

<input list="browsers" name="myBrowser" />
<datalist id="browsers">
<option value="Chrome">
<option value="Firefox">
<option value="Internet Explorer">
<option value="Opera">
<option value="Safari">
</datalist>
In Chrome/Edge/Safari, clicking on this input once, opens the datalist. However in FireFox, it requires a second click on the input element to open the datalist. Is there a way to get this behavior consistent with other browsers?
The expected result is for a single click to open the data list, just as works in other browsers.

Related

Strange values in Datalist Input 'Gas' 'gas'

If I set the name or id of an Input with a list like 'cia' two strange selectable values appear at the bottom of it. Gas and gas.
Any idea why?
<input list="browsers" id="cia">
<datalist id="browsers">
<option value="Internet Explorer">
<option value="Firefox">
<option value="Chrome">
<option value="Opera">
<option value="Safari">
</datalist>
Fiddle https://jsfiddle.net/fredsaavedra/ktwrpjby/
You might have typed it into a datalist with the same ID before and your browser has cached it. Try incognito mode and they should be gone.
You can try and prevent caching with the answers mentioned here
How to turn off autocomplete while keep using datalist element in html

Disable custom input in HTML input dropdown

Good day!
I've got a simple problem, and it involves HTML.
I've googled everywhere, but found only similar results for, "How to disable autocomplete on input".
I'm trying to find a way to block custom input for a dropdown selection input, but I can't seem to find it.
I've found the attribute disabled, and setting disabled="true" on the input completely disables it, which is not my goal.
This is my code, I found it on w3schools.com.
I've attached 2 versions of it, un-disabled and disabled.
<!--NOT DISABLED STUFF-->
<form action="/action_page.php">
<input style="margin-bottom:15vw;" list="browsers">
<datalist id="browsers">
<option value="Internet Explorer">
<option value="Firefox">
<option value="Chrome">
<option value="Opera">
<option value="Safari">
</datalist>
</form>
<!--DISABLED STUFF-->
<form action="/action_page.php">
<input list="browsers" disabled="true">
<datalist id="browsers">
<option value="Internet Explorer">
<option value="Firefox">
<option value="Chrome">
<option value="Opera">
<option value="Safari">
</datalist>
</form>
Thank you for reading :)
I found a way to do it, thanks to #Eisenheim's comment.
Instead of using <datalist> stuff, it works when I use <select>.
<form action="default.php">
<select>
<option value=""></option>
<option value="Internet Explorer">Internet Explorer</option>
<option value="Firefox">Firefox</option>
<option value="Chrome">Chrome</option>
<option value="Opera">Opera</option>
<option value="Safari">Safari</option>
</select>
<input type="submit">
</form>

How to hide a datalist's options using CSS

Given the following code:
<label for="myBrowser">Choose a browser from this list:</label>
<input list="browsers" id="myBrowser" name="myBrowser" />
<datalist id="browsers">
<option value="Chrome">
<option value="Firefox">
<option value="Internet Explorer">
<option value="Opera">
<option value="Safari">
<option value="Microsoft Edge">
</datalist>
The following UI is rendered:
What CSS can be added without changing the HTML and without using JavaScript to take away the auto-completed items so it behaves like a datalist-less input?
The following UI is desired:
It is not solved with css, but try use autocomplete="off" in your input

HTML Datalist Tag - Match Beginning Of String Only

I want to use an HTML datalist tag drop-down, but only want the options that match to correspond to the beginning of the string entered. For example:
<label>Choose a browser from this list:
<input list="browsers" name="myBrowser" /></label>
<datalist id="browsers">
<option value="Chrome">
<option value="Firefox">
<option value="Internet Explorer">
<option value="Opera">
<option value="Safari">
<option value="Microsoft Edge">
</datalist>
If you type in "O" into the search bar, rather than just showing "Opera" as a result, it will show every result with an "o". Checking for other answers, I found this question: How to make datalist match result from beginning only, and the answer comes quite close, but won't suggest the result until it's finished ("O", "Op", "Ope", etc.) won't display "Opera"; only typing in the full word will show the result.

Is there a potential way to disable user input in a <datalist>?

I'm debating between using a <select> or <datalist> to display a drop-down list from which the user can select the items.
One downside of the <select> tag is that it's inconsistent as it renders differently in different browsers: some browsers it displays with scroll bar, and for some it's a drop-down list.
The <datalist> on the other hand seems good but I just want to know if there is any way to disable the text input where the user can type whatever they want in the text box if they don't click the down arrow button on the input field as shown:
​<form action="demo_form.asp" method="get">
<input list="browsers" name="browser">
<datalist id="browsers">
<option value="Internet Explorer">
<option value="Firefox">
<option value="Chrome">
<option value="Opera">
<option value="Safari">
</datalist>
<input type="submit">
</form>
Is there someway to disable the input bar while keeping the dropdown list? I tried the 'readonly' attribute but that renders the whole non-clickable.
You could use the pattern attribute on the input element to restrict the allowed values:
​<form action="demo_form.asp" method="get">
<input list="browsers" name="browser"
pattern="Internet Explorer|Firefox|Chrome|Opera|Safari"
title='Must be "Internet Explorer", "Firefox", "Chrome", "Opera", or "Safari"'>
<datalist id="browsers">
<option value="Internet Explorer">
<option value="Firefox">
<option value="Chrome">
<option value="Opera">
<option value="Safari">
</datalist>
<input type="submit">
</form>