django-multiselectfield
django-multiselectfield copied to clipboard
When customizing template - data stored in database is not taken (editing form)
Hi!
when I switched from
{% for item in filed %}
<label class="form-check-label" for="{{filed.auto_id}}">{{ item }}</label>
{% endfor %}
to
<b><p><label for="{{filed.id_for_label}}">{{ filed.label }}</label></p></b>
{% for value, text in filed.field.choices %}
<label class="form-check-label" for="{{filed.auto_id}}_{{ forloop.counter0 }}">
<input type="radio" name="{{ filed.name }}" style="display:none" value="{{ value }}" id="{{filed.auto_id}}_{{ forloop.counter0 }}">
<span class="checkmark">{{ text }}</span>
</label>
{% endfor %}
In my template for editing previously stored data radio fields are not checked to indicate what data was stored when it was created. this code is part of single_choice_radio_field.html and it is used as such
{% include 'includes/single_choice_radio_field.html' with filed=flat_form.heating %}
@temonuv i have the same problem! how to resolve? inside admin working but is forms outside show empty select input
so long ago.... sorry I don't remember now and I have abandoned the project where it was used
If want to edit the form and load the data saved on the database you must add to the input tag
"{% if value in checked_values %} checked="checked"{% endif %}
Then save the values list in a variable on your views as checked_values and pass it to the template.
return render(request, 'page.html', {'checked_values': values_list})