Custom Widget to select content/invisible radio input
This commit is contained in:
parent
74d842a668
commit
8b32b56dd9
@ -2,9 +2,7 @@
|
|||||||
|
|
||||||
<div class="LP-Input {% if classes%}{{classes}}{% endif %} {% if field.errors %} LP-Input--error {% endif %}">
|
<div class="LP-Input {% if classes%}{{classes}}{% endif %} {% if field.errors %} LP-Input--error {% endif %}">
|
||||||
<label for="{{field.id_for_label}}" class="LP-Input__Label">{{field.label}}</label>
|
<label for="{{field.id_for_label}}" class="LP-Input__Label">{{field.label}}</label>
|
||||||
{% with class="LP-Input__Field "%}
|
{% render_field field class+='LP-Input__Field' %}
|
||||||
{% render_field field class=class%}
|
|
||||||
{% endwith %}
|
|
||||||
|
|
||||||
<span class="LP-Input__Message">
|
<span class="LP-Input__Message">
|
||||||
{% if field.errors %}
|
{% if field.errors %}
|
||||||
|
@ -0,0 +1,23 @@
|
|||||||
|
<ul class="{{widget.attrs.container_class}}">
|
||||||
|
{% for group_name, group_choices, group_index in widget.optgroups %}
|
||||||
|
{% for option in group_choices %}
|
||||||
|
{% if option.value %}
|
||||||
|
<li style="display: content;">
|
||||||
|
<input
|
||||||
|
style="display: none;"
|
||||||
|
name="{{option.name}}"
|
||||||
|
id="{{widget.attrs.id}}{{group_index}}"
|
||||||
|
type="radio"
|
||||||
|
value="{{option.value.instance.id}}"
|
||||||
|
{% if widget.attrs.current_selected_value|stringformat:'s' == option.value.instance.id|stringformat:'s' %}checked="checked"{% endif %}
|
||||||
|
/>
|
||||||
|
<label class="{{widget.attrs.item_class}}" for="{{widget.attrs.id}}{{group_index}}">
|
||||||
|
{% if widget.attrs.item_template %}
|
||||||
|
{% include widget.attrs.item_template with object=option.value.instance %}
|
||||||
|
{% endif %}
|
||||||
|
</label>
|
||||||
|
</li>
|
||||||
|
{% endif %}
|
||||||
|
{% endfor %}
|
||||||
|
{% endfor %}
|
||||||
|
</ul>
|
5
django_lostplaces/lostplaces/widgets.py
Normal file
5
django_lostplaces/lostplaces/widgets.py
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
from django import forms
|
||||||
|
|
||||||
|
class SelectContent(forms.Select):
|
||||||
|
template_name = 'widgets/select_content.html'
|
||||||
|
|
Loading…
Reference in New Issue
Block a user