在bootstraps模式中显示表单错误消息

时间:2018-01-08 07:50:39

标签: javascript jquery twitter-bootstrap django-views

我有一个在模板中呈现的登录表单,我想在引导模式中提交错误结果或错误格式时显示错误消息。

<!--- modal start--->
<div class="modal fade" id="loginform" tabindex="-1" role="dialog" aria-labelledby="exampleModalCenterTitle" aria-hidden="true">
  <div class="modal-dialog" role="document">
    <div class="modal-content">
      <div class="modal-header modalheader">
        <h5 class="modal-title" id="exampleModalLongTitle">Error</h5>
        <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                                        <span aria-hidden="true">&times;</span>
                                    </button>
      </div>
      <div class="modal-body">
        <span class='form-errors'>
                                            {% for error in form.non_field_errors %}
                                                <li>{{ error }}</li>
                                            {% endfor %}
                                        </span>
      </div>
      <div class="modal-footer">
        <button type="submit" class="btn btn-success">Ok</button>
        <button type="button" class="btn btn-secondary" data-dismiss="modal">
                                                Cancel
                                            </button>
      </div>
    </div>


  </div>


</div>
<!--- modal end---->

这是触发模态的java脚本

<script>$('#loginform').on('form-errors', function (e) {
    // Show the message modal
    $('#messageModal').modal('show');
});</script>

0 个答案:

没有答案