【问题标题】:Django - CheckboxSelectMultiple() with scrollbarDjango - 带有滚动条的 CheckboxSelectMultiple()
【发布时间】:2019-05-17 13:16:39
【问题描述】:

我将在表单上有一百多个复选框。这现在看起来很难看。我正在尝试使复选框位于带有垂直滚动条的框架(?)中。以酥脆的形式使用height:100px; 根本没有任何影响。在 attrto CheckboxSelectMultiple()ModelMultipleChoiceField 中使用相同的内容会引发 unexpected argument attr 错误。

表单域:

specialities = forms.ModelMultipleChoiceField( queryset=spQry ,widget = forms.widgets.CheckboxSelectMultiple(),  label=_('Speciality'), required=True)

脆弱的形状部分:

 self.helper = FormHelper()
        self.helper.layout = Layout(
            Field('practice_date'),
            Field('gender'),
            Field('specialities', style='max-height:20px!important'),
            StrictButton("Submit", name="submit", value="Submit", type='submit' ,css_class='btn btn-action-success')
        )

还有那个滚动条吗?

谢谢

【问题讨论】:

  • 你能把style='overflow-y: scroll;'添加到你的html元素吗

标签: django django-crispy-forms


【解决方案1】:

更新你脆弱的表单部分:

self.helper = FormHelper()
self.helper.layout = Layout(
    Field('practice_date'),
    Field('gender'),
    Field(Div('specialities', css_class="scrollbar-y")),
    StrictButton("Submit", name="submit", value="Submit", type='submit' ,css_class='btn btn-action-success')

)

并将此代码添加到您的样式表中

.scrollbar-y{
   overflow-y: scroll !important;
   max-height:20px !important;
}

【讨论】:

  • 对表单没有任何影响。
  • 去掉酥脆的部分告诉答案
  • 还是不行。这部分实际上是将class 应用于单个复选框而不是它们的组。我在开发者工具中检查了这个
  • 更新答案
  • 请检查并告诉我
猜你喜欢
  • 2018-10-18
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-04-06
  • 2012-03-19
  • 2016-03-20
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多