首页 > 解决方案 > 覆盖 Crispy Forms 的 Fieldset 中的标签偏移量

问题描述

我的布局中有一个 Fieldset,它在第一行包含一个复选框。对于我设置的主要形式:

self.helper.layout_class = "create-label col-md-2"

它对齐我的标签和字段并创建一个“偶数”表单。

问题是,这被应用在一个字段集中,一个复选框被打乱到右边,描述在右边,看起来它只是挂在屏幕中间: 屏幕中间的复选框

这是因为生成的 html 正在应用为标签生成的偏移量,最终看起来像这样:

<div class="form-group row"> 
   <div class="offset-md-2 col-md-10">
      <div id="div_id_allow_invitees_to_add_others" class="custom-control custom-checkbox">
         <input type="checkbox" name="allow_invitees_to_add_others" class="checkboxinput custom-control-input" id="id_allow_invitees_to_add_others"> 
         <label for="id_allow_invitees_to_add_others" class="custom-control-label">
         Allow invitees to add others
         </label>

如果我手动删除offset-md-2浏览器检查器中FieldsetDiv那一点布局相当简单:

            Div(
                Fieldset(
                    _("Invitees"),
                    Field("allow_invitees_to_add_others"),
                    Formset("invitees"),
                ),
                css_class="",
            ),

任何人都可以告诉我如何让这个复选框在左边!

标签: djangodjango-formsdjango-templatesdjango-crispy-forms

解决方案


推荐阅读