django多个MultipleChoiceField旁边的项目符号

polhcujo  于 2023-08-08  发布在  Go
关注(0)|答案(3)|浏览(108)

我有一个带有CheckboxSelectMultiple部件的2 MultipleChoiceField的表单。
当在模板中呈现时,复选框在每个选项的左侧都有一个“项目符号”。
我认为这与复选框渲染有关,但我不确定如何删除项目符号?
反馈非常感谢。

表单

class GameScheduleForm(forms.Form):

    weight_training_days = forms.MultipleChoiceField(widget=forms.CheckboxSelectMultiple,
        choices=(
            (0, "MONDAY"),
            (1, "TUESDAY"),
            (2, "WEDNESDAY"),
            (3, "THURSDAY"),
            (4, "FRIDAY"),
            (5, "SATURDAY"),
            (6, "SUNDAY"),
        ),
    )

    cardio_training_days = forms.ChoiceField(widget=forms.CheckboxSelectMultiple,
        choices=(
            (0, "MONDAY"),
            (1, "TUESDAY"),
            (2, "WEDNESDAY"),
            (3, "THURSDAY"),
            (4, "FRIDAY"),
            (5, "SATURDAY"),
            (6, "SUNDAY"),
        ),
    )

字符串

模板

{% extends "fitgames/fitgames_base.html" %}

{% block content %}
<div class="row-fluid">
    <div class="well game span4 offset4">
        <div class="row-fluid">
            <h4 class="text-center">Total Body HIT</h4>
            <p class="text-center">Select the days you can workout</p>
        </div>
        <div class="row-fluid">
            <form method="post" action="{% url 'game_setup2_schedule' %}"> {% csrf_token %}
                <div><strong>Select 3 Weight Training Days</strong></div>
                <div>{{ form.weight_training_days}}</div>
                <div><strong>Select 3 Cardio Days</strong></div>
                <div>{{ form.cardio_training_days }}</div>
                <div><button class="btn btn-primary btn-large" type="submit">&nbsp;Next</button></div>
            </form>
        </div>
    </div>
</div>


{% endblock %}

ffvjumwh

ffvjumwh1#

呈现forms.CheckboxSelectMultiple时,它呈现在ul标记中。你需要做的是将以下内容添加到CSS中(根据需要使其更具体地适用于该表单):

ul
{
    list-style-type: none;
}

字符串

jvlzgdj9

jvlzgdj92#

这就去掉了项目符号,而不添加css。:)

{% for checkbox in form.Context %}
<div class="checkbox">
    <label>
            {{ checkbox.tag }} {{ checkbox.choice_label }}
    </label>
</div>
{% endfor %}

字符串

e37o9pze

e37o9pze3#

我发现在form类中定义最简单

widget= forms.CheckboxSelectMultiple(
        attrs={
            'class': "list-unstyled"
        }
    )

字符串

相关问题