Use overridden input.html & attrs.html

This commit is contained in:
sonny 2020-06-02 20:34:29 +02:00
parent 89556e225c
commit a760bd6188
6 changed files with 32 additions and 7 deletions

View file

@ -1,7 +1,7 @@
{% load filters %} {% load filters %}
{% with option.instance|id_for_label:"category" as id_for_label %} {% with option.instance|id_for_label:"category" as id_for_label %}
{% include "components/form/checkbox.html" with name=option.name value=option.value|stringformat:'s' id=id_for_label id_for_label=id_for_label checked=option.selected only %} {% include "components/form/checkbox.html" with widget=option checked=option.selected id_for_label=id_for_label only %}
{% endwith %} {% endwith %}
{% if option.instance.favicon %} {% if option.instance.favicon %}

View file

@ -0,0 +1,18 @@
{% spaceless %}
{% for name, value in widget.attrs.items %}
{% if value is not False %}
{{ name }}
{% if value is not True %}
="{{ value|stringformat:'s' }}"
{% endif %}
{% endif %}
{% endfor %}
{% if id %} id="{{ id }}"{% endif %}
{% if type %} type="{{ type }}"{% endif %}
{% if value %} value="{{ value }}"{% endif %}
{% if name %} name="{{ name }}"{% endif %}
{% if data_input %} data-input="{{ data_input }}"{% endif %}
{% if checked %} checked {% endif %}
{% endspaceless %}

View file

@ -1,12 +1,10 @@
<div class="checkbox"> <div class="checkbox">
{% if field %} {% if widget %}
{{ field }} {% include "components/form/input.html" with widget=widget %}
{% else %} {% else %}
<input id="{{ id }}" name="{{ name }}" type="checkbox" value="{{ value }}" {% include "components/form/input.html" with id=id name=name type="checkbox" value=value data_input=data_input checked=checked %}
{% if data_input %}data-input="{{ data_input }}"{% endif %}
{% if checked %}checked{% endif %} />
{% endif %} {% endif %}
<label class="checkbox__label" for="{% if field %}{{ field.id_for_label }}{% else %}{{ id_for_label }}{% endif %}"> <label class="checkbox__label" for="{% if widget %}{{ widget.attrs.id }}{% else %}{{ id_for_label }}{% endif %}">
<span class="checkbox__box"/> <span class="checkbox__box"/>
</label> </label>
</div> </div>

View file

@ -0,0 +1,7 @@
{% spaceless %}
<input {% if widget %}
type="{{ widget.type }}" name="{{ widget.name }}"
{% if widget.value != None %} value="{{ widget.value|stringformat:'s' }}"{% endif %}
{% endif %}
{% include "django/forms/widgets/attrs.html" %}>
{% endspaceless %}

View file

@ -0,0 +1 @@
../../../components/form/attrs.html

View file

@ -0,0 +1 @@
../../../components/form/checkbox.html