gpt4 book ai didi

flask - 将 Bootstrap 模式按钮映射到 Flask WTF 提交

转载 作者:行者123 更新时间:2023-12-02 13:16:51 26 4
gpt4 key购买 nike

我已经在 Flask Web 应用程序中渲染了一个表单。对于我的特定用例,我想添加一个模式对话框窗口来“确认”用户的选择。我可以显示模式,但我无法弄清楚如何将“确认”按钮(在模式中)映射到表单操作。引导文档上的示例不包括示例中的按钮映射。

{% extends "base.html" %}
{% import "bootstrap/wtf.html" as wtf %}
<unrelated content>
...
</unrelated content>
...
<h4>Enter the email address of the employee receiving the unit</h4>
<div class="col-lg-3">
<div class="row">
<form class="form" id="emailForm" action="{{ url_for('main.transfer', serial=system.serial) }}" method="POST">
{{ mail_form.hidden_tag() }}
{{ mail_form.email }}
{{ mail_form.submit }}<!-- ###THIS IS WHAT I WANT THE MODAL CONFIRM TO TRIGGER -->
<!-- Button trigger modal -->
<button type="button" class="btn btn-primary" data-toggle="modal" data-target="#exampleModal">
Transfer
</button>
</form>
</div>
</div>

<!-- Modal -->
<div class="modal fade" id="exampleModal" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel" aria-hidden="true">
<div class="modal-dialog modal-dialog-centered" role="document">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="exampleModalLabel">Unit Transfer</h5>
<!--<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">&times;</span>
</button>-->
</div>
<div class="modal-body">
You are transferring a unit from {{ system.assignee.email }} to another user. Are you sure?
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-dismiss="modal">Cancel</button>
<button type="button" class="btn btn-success success" type="submit" data-target="#emailForm.submit()">Confirm</button>
</div>
</div>
</div>
</div>

如何告诉模式当单击“提交”按钮时我想要发生什么?我能找到的所有文档都讨论了将整个表单放入模式中,但这不是我想要的。

提前致谢。

最佳答案

进行以下更改,

  • 更改{{ mail_form.submit }}{{ mail_form.submit(hidden='true', id='form-submit') }}隐藏提交按钮。
  • 更改<button type="button" class="btn btn-success success" type="submit" data-target="#emailForm.submit()">Confirm</button><button type="button" class="btn btn-success success" id="modal-confirm">Confirm</button>
  • 添加 jquery 后添加以下脚本,

    <script>

    $('#modal-confirm').click(function(){
    // Perform the action after modal confirm button is clicked.

    $('#form-submit').click(); // submitting the form
    });

    </script>

我希望这会有所帮助。

关于flask - 将 Bootstrap 模式按钮映射到 Flask WTF 提交,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49264419/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com