HTML5 Datalist
One of the most used JavaScript widgets over the past decade has been the text box autocomplete widget. Every JavaScript framework has their own autocomplete widget and many of them have become quite advanced. Much like the placeholder attribute's introduction to markup, a frequently used functionality has been moved from a JavaScript-only utility to HTML via the new DATALIST
element.
The HTML
A DATALIST
element gets an ID
attribute and contains numerous OPTION
elements, just as a SELECT
element would:
<datalist id="frameworks"> <option value="MooTools"> <option value="Moobile"> <option value="Dojo Toolkit"> <option value="jQuery"> <option value="YUI"> </datalist>
Once the DATALIST
element is in place, a list attribute gets added to an INPUT
element which refers to the list ID
:
<input name="frameworks" list="frameworks" />
What's provided is a very rudimentary but useful autocomplete list of existing items that match given text. Of course the lack of styling that comes with OPTION
elements isn't optimal, and there's no method to hook DATALIST
's up to a service endpoint for more dynamic suggestions, but this new element is a step in the right direction!
Alas, non-functional on Android JB default browser.