简体   繁体   中英

Django formtools SessionWizardView repopulating form on validation error

I've a django-formtools SessionWizardView wizard which works fine when all data is input. However, I have form validation going on within each step of the form and if a step is represented I cannot get the entered data to redisplay in some instances.

Here is a simple example. Required field description isn't entered byt field plan was entered. The validation error is reported and the form redisplayed.

I'm creating the plan checkboxes in the template as below.

{% for plan in PLANS %}
    <div class="col-6">
         <span class="form-radio form-radio-xl">
             <input type="radio" id="id_job-plan_{{plan.id}}" name="job-plan" value="{{ plan.pk }}" required {% if wizard.form.plan.value == plan.pk %}checked{% endif %}>
              <label for="id_job-plan_{{plan.id}}">{{ plan }} - {{plan.pk}} </label>
         </span>
    </div>
{% endfor %}

I expect {% if wizard.form.plan.value == plan.pk %}checked{% endif %} to be True in one instance and therefore checked . It isn't and I do not understand why not.

If I do {{ wizard.form.plan.value }} the displayed result looks the same as {{ plan.pk }}

Found the answer. It looks the same but {{ wizard.form.plan.value }} is a string. By using {{ wizard.form.plan.value|add:"0" }} I coerce it into an integer and now it works

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM