Closed kezabelle closed 9 years ago
Oh, my handling of optgroups is horrendous. Let me find a snippet.
Something like:
{% block options %}
{% for option_value, option_label in choices %}
{# Handle optgroups #}
{% if option_label.0|length > 1 %}
<optgroup label="{{ option_value }}">
{% for opt_value, opt_label, attrs in option_label %}
{% widget 'form:option' option_label=opt_label option_value=opt_value %}
{% endfor %}
</optgroup>
{% elif option_template %}
{% widget option_template %}
{% else %}
{% widget 'form:option' %}
{% endif %}
{% endfor %}
{% endblock %}
{% block select %}
<span class="uk-select-wrapper">
<select {% widget 'form:attrs' %}>
{% if widget.choices %}
{% widget 'form:options' choices=widget.choices %}
{% else %}
{% widget 'form:options' %}
{% endif %}
</select>
</span>
{% endblock %}
{% block option %}
<option value="{{ option_value }}"
{% if value == option_value|stringformat:'s' %}selected{% endif %}
{% if multiple and option_value|stringformat:'s' in value %}selected{% endif %}
{% if option_value.seconds != None %}data-seconds={{ option_value.seconds }}{% endif %}
{% if attrs %}
{% for k, v in attrs.items %}{{ k }}={{ v }} {% endfor %}
{% endif %}
>
{{ option_label }}
</option>
{% endblock %}
Given a
choices
of (from the docs):the existing implementation doesn't do the same as Django's
Select
widget. This is me hacking out support for handling that use case.WIP because:
choices
)the new wrapper object should be backwards compatible with the old choices format I think, but thoughts and feedback would be appreciated.