带有 CheckboxSelectMultiple 的 django choiceField:默认全部选中? [英] django choiceField with CheckboxSelectMultiple: all selected by default?

查看:26
本文介绍了带有 CheckboxSelectMultiple 的 django choiceField:默认全部选中?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在将 choiceField 与 CheckboxSelectMultiple 小部件一起使用.默认情况下是否可以将所有复选框呈现为选中状态?谢谢!

I'm using a choiceField with the CheckboxSelectMultiple widget. Is it possible to render all checkboxes as checked by default? Thanks!

推荐答案

我正在使用这个的表单做这个

I am doing exactly that on a form using this

class MyForm(forms.Form):
     photo_list = forms.MultipleChoiceField(
         label="Photos", 
         required=False, 
         help_text="Unselect the photos you want to delete", 
         choices=(), 
         widget=forms.CheckboxSelectMultiple(attrs={"checked":""})
     )

这篇关于带有 CheckboxSelectMultiple 的 django choiceField:默认全部选中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆