我正在Django中制作一个网站,其中我正在使用Django Form,我的字段是
admin = forms.BooleanField(
required=False,
widget=forms.CheckboxInput(),
label=(u'Admin for the account')
)
owner = forms.BooleanField(
required=False,
widget=forms.CheckboxInput(),
label=(u'Owner for the account')
)
在我的html页面中我想要一个提交按钮,单击它将显示一个弹出窗口,其中您有一个确定按钮,单击该按钮时所有者的值(复选框)将消失。
来自Form class
的文档
请注意,它不包括
<form>
标记或submit
按钮。我们必须在模板中自己提供这些。
至于以下附加功能:
在我的html页面中,我想要一个提交按钮,点击它会显示 一个弹窗,其中你有一个确定按钮,点击哪个值 的所有者(复选框)将消失。
如果要执行此操作,则需要编写自定义 JavaScript 函数。您可以使用jquery
插件。这里有更多关于使用 jquery 提交表单的文档和其他处理。
您必须在 html 中手动包含提交按钮。
示例代码:请注意,我使用了引导模态。
<form action="" method="post">{% csrf_token %}
<!-- your input field will go here -->
<!-- Small modal -->
<button type="button" class="btn btn-primary" data-toggle="modal" data-target=".bs-example-modal-sm">Submit</button>
<div class="modal fade bs-example-modal-sm" tabindex="-1" role="dialog" aria-labelledby="mySmallModalLabel">
<div class="modal-dialog modal-sm">
<div class="modal-content">
<input type="checkbox" name="user" value="user"><br>
<input type="submit" value="Okay">
</div>
</div>
</div>
</form>