【问题标题】:Django crispy-forms shows errors above InlineRadios but below othersDjangocrispy-forms 在 InlineRadios 上方显示错误,但在其他错误下方
【发布时间】:2015-11-13 21:16:13
【问题描述】:

在模型中

class TourLead(models.Model):
    GENDER_CHOICES = (
        ('M', 'Male'),
        ('F', 'Female'),
    )

    name = models.CharField(max_length=256)
    gender = models.CharField(max_length=1, choices=GENDER_CHOICES)

在表格中

gender = forms.ChoiceField(widget=forms.RadioSelect(), choices=TourLead.GENDER_CHOICES)

这是布局:

Layout(
        Field('name', placeholder='John Doe'),
        InlineRadios('gender'),
        # ...
    )

我的问题是我如何才能始终在输入之后放置错误?

我已经尝试了一些 css:

[id^="error"] {
    position: absolute;
    top: 100%;
    width: 100%;
}

但无法弄清楚如何在...之后显示某种间隔(边距...)

【问题讨论】:

    标签: css django django-forms django-crispy-forms


    【解决方案1】:

    我已经解决了这个指定的自定义模板

    InlineRadios('gender', template='radioselect_inline.html'),
    

    只需将它和radioselect.htmlsite-packages/... 复制到您的静态文件夹,然后将“radioselect_inline.html”中的最后一个包含更改为

    {% include 'radioselect.html' %}
    

    radioselect.html 中将{% include 'bootstrap3/layout/field_errors_block.html' %} 移动到末尾,如下所示

        #...
        {% endfor %}
    
        {% include 'bootstrap3/layout/field_errors_block.html' %}
        {% include 'bootstrap3/layout/help_text.html' %}
    </div>
    

    此时您还将面临错误 https://github.com/maraujop/django-crispy-forms/issues/361,因此只需降级到 django-crispy-forms==1.4.0 即可!

    【讨论】:

      猜你喜欢
      • 2019-07-19
      • 2012-05-04
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-01-10
      • 2022-01-26
      • 1970-01-01
      相关资源
      最近更新 更多