Django - 在模态对话框引导程序中不会发生表单验证

时间:2016-08-01 15:02:55

标签: python django twitter-bootstrap

以下是我的forms.py

的代码
class Register(forms.Form):
    username = forms.CharField(label='', max_length=64,
                               widget=forms.TextInput({
                                   'placeholder': 'User Name'}))
    firstname = forms.CharField(label='', max_length=64,
                                widget=forms.TextInput({
                                   'placeholder': 'First Name'}))
    surname = forms.CharField(label='', max_length=64,
                              widget=forms.TextInput({
                                   'placeholder': 'Sur Name / Second Name'}))
    email = forms.EmailField(label='', max_length=64,
                              widget=forms.TextInput({
                                   'placeholder': 'Email'}))

在简单的html文件中显示表单时,表单验证正在进行,而它在模式对话框窗口中不起作用。模态对话框窗口的html代码如下:

<div class="col-md-12 text-center">
    <button type="button" class="btn btn-primary" data-toggle="modal" data-target="#ApplyJob">Apply for Job</button>
</div>
<div id="ApplyJob" class="modal fade" role="dialog">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <div class="modal-title">
                    <button type="button" class="close" data-dismiss="modal">&times;</button>

                </div>
            </div>
            <form action="" method="post"> {% csrf_token %}
                <div class="modal-body">
                    {{ form|crispy }}

                </div>
                <div class="modal-footer">
                    <input type="submit" value="Apply" class="btn btn-primary"/>
                </div>
            </form>
        </div>
    </div>
</div> 

它显示模态窗口并获取输入但表单验证没有发生,请帮我这个。我是Django的新手。

0 个答案:

没有答案