0

以下是我要求用户为基于选择的问题输入 n 个选项/选项的部分代码。现在,由于正确的选择将成为表单集形式输入的选择之一。因此,我想使用 jquery 动态填充我的正确选择选择字段。但为此,我需要表单集形式的所有值。是,有任何内置的方法可以做到这一点。

<div class="row marginTop35">
    <div class=" col s5">
        {{ choice_formset.management_form }}
        {% for choice_form in choice_formset.forms %}
            <div class="choice-item">
                <div class="row margin0">
                    <label>
                        <div class="input-field col s11">
                            <i id="{{ choice_form.choice.id_for_label }}_icon" class="material-icons prefix">label_outline</i>
                            <input name="{{ choice_form.choice.html_name }}" id="{{ choice_form.choice.id_for_label }}" type="text" class="validate" value="{{ choice }}">
                            <label id="{{ choice_form.choice.id_for_label }}_label" for="{{ choice_form.choice.id_for_label }}" data-error="{% if email_error_message %}{{ email_error_message }}{% else %}Enter valid choice{% endif %}">Choice </label>
                        </div>
                        <div class="col s1 lineHeightInherit">
                            <a class="btn-floating red darken-1 delete-choice">
                                <i id="{{ choice_form.choice.id_for_label }}_icon" class="material-icons right">delete</i>
                            </a>
                        </div>
                    </label>
                </div>
            </div>
        {% endfor %}
        <div class="margin0">
            <a id="add-choice" class="waves-effect waves-light btn-floating indigo accent-2" style="margin-left: 42px;">
                <i class="material-icons">add</i>
            </a>
        </div>
    </div>
    <div class="input-field col s5 right">
        <i id="{{ form.correct_choice.id_for_label }}_icon" class="material-icons prefix">label</i>
        <select name="{{ form.correct_choice.html_name }}" {% block select_multiple %}{% endblock %} >
            <option value="" selected disabled>Choose correct choice</option>
            <option value="dummy">dummy choice</option>
        </select>
        <label>Correct Choice</label>
    </div>
</div>
4

0 回答 0