﻿id	summary	reporter	owner	description	type	status	component	version	severity	resolution	keywords	cc	stage	has_patch	needs_docs	needs_tests	needs_better_patch	easy	ui_ux
32125	Added basic support for <datalist> elements for suggestions in Input widgets	Volodymyr	nobody	"HTML5 introduces a support for {{{<datalist>}}} '''HTML5''' elements for suggestions in '''input''' tag

To do this in Django currently, you have to do something like:

'''django/forms/widgets/datalist.html'''
{{{
{% include ""django/forms/widgets/input.html"" %}
<datalist id=""{{ widget.id }}"" name=""{{ widget.name }}""{% include ""django/forms/widgets/attrs.html"" %}>{% for group_name, group_choices, group_index in widget.optgroups %}{% if group_name %}
  <optgroup label=""{{ group_name }}"">{% endif %}{% for option in group_choices %}
  {% include option.template_name with widget=option %}{% endfor %}{% if group_name %}
  </optgroup>{% endif %}{% endfor %}
</datalist>
}}}

'''django/forms/widgets/datalist_option.html'''
{{{
<option value=""{{ widget.value|stringformat:'s' }}""{% include ""django/forms/widgets/attrs.html"" %}>
}}}

'''django/forms/widgets.py'''
{{{#!python
class Datalist(Select):
    input_type = 'text'
    template_name = 'django/forms/widgets/datalist.html'
    option_template_name = 'django/forms/widgets/datalist_option.html'
    add_id_index = False
    checked_attribute = {'selected': True}
    option_inherits_attrs = False
}}}

'''django/forms/fields.py'''
{{{#!python
class DatalistField(ChoiceField):
    widget = Datalist
    default_error_messages = {
        'invalid_choice': _('Select a valid choice. %(value)s is not one of the available choices.'),
    }

    def __init__(self, *, choices='', **kwargs):
        super().__init__(**kwargs)
        self.choices = choices
}}}"	New feature	new	Forms	dev	Normal		datalist, forms, html5		Unreviewed	0	0	0	0	0	1
