goinnn / django-multiselectfield

A Multiple Choice model field
GNU Lesser General Public License v3.0
450 stars 208 forks source link

When customizing template - data stored in database is not taken (editing form) #92

Open temonuv opened 6 years ago

temonuv commented 6 years ago

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 %}
CARocha commented 4 years ago

@temonuv i have the same problem! how to resolve? inside admin working but is forms outside show empty select input

temonuv commented 4 years ago

so long ago.... sorry I don't remember now and I have abandoned the project where it was used

Abcaran commented 3 years ago

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})