简体   繁体   English

重定向之前将Modal用作确认

[英]Implementing Modal as confirmation before redirecting

I am currently trying to implement a table that, when a row is clicked on, will display a modal that acts as a confirmation page where the user can then submit the information. 我当前正在尝试实现一个表,当单击某行时,该表将显示一个用作确认页面的模式,然后用户可以在其中提交信息。 When the user clicks on the submit in the modal, it needs to add the row data to a sql database and redirect the user to another page. 当用户单击模式中的提交时,它需要将行数据添加到sql数据库中,并将用户重定向到另一个页面。 I am stuck on how to pass the information that the user clicks on to my python code where I can add it to sql and I can't get the page to redirect. 我被困在如何将用户单击的信息传递到我的python代码上,在那里我可以将其添加到sql中,而我无法使页面重定向。

This is my table tag 这是我的桌子标签

<tr class="room" data-id="{{ res.room_id }}" data-toggle="modal" data-target="#orderModal" >

This is my modal 这是我的情态

<div id="orderModal" class="modal fade" role="dialog" aria-labelledby="orderModal" aria-hidden="true">
  <div class="modal-dialog">
    <div class="modal-content">
      <div class="modal-header">
        <h2>Order</h2>
        <button type="button" class="close" data-dismiss="modal" aria-hidden="true">x</button>
      </div>
      <div id="orderDetails" class="modal-body"></div>
      <div id="orderItems" class="modal-body"></div>

      <div class="modal-footer">
           <button type="button" class="btn btn-default" data-dismiss="modal">Cancel</button>
            <a href="#" id="submit" type="submit" class="btn btn-success">Submit</a>
      </div>
    </div>
  </div>
</div>

</div>

This is my javascript 这是我的JavaScript

$('#orderModal').modal({
        keyboarnd: true,
        backdrop: "static",
        show:false,

    }).on('show.bs.modal', function(){
          var getIdFromRow = $(this).data('orderid');
        //make your ajax call populate items or what even you need
        $(this).find('#orderDetails').html($('<b> Order Id selected: ' + getIdFromRow  + '</b>'))
    });

    $(".table-striped").find('tr[data-target]').on('click', function(){
        //or do your operations here instead of on show of modal to populate values to modal.
         $('#orderModal').data('orderid',$(this).data('id'));
    });

This is my python pseudocode 这是我的python伪代码

@app.route("/table", methods=["GET", "POST"])
@login_required
def book():
     # """Confirm the room you have selected to book"""

     # User reached route via POST (as by submitting a form via POST) --> BUT ONLY BY CLICKING OK BUTTON, NOT CANCEL BUTTON
    if request.method == "POST":

         # Update bookings with user's booking
         # Redirect to history.html where it displays a table of only your history of bookings (date, start time, end time, room)

          return redirect("/")

    else:
        return render_template("history.html")

Thank you for any help! 感谢您的任何帮助!

You can use Bootbox.js for confirmation modal 您可以使用Bootbox.js进行确认模式

http://bootboxjs.com http://bootboxjs.com

I do not know much about python, but from what I understand from your question it seems like you want to get the table row that you clicked to the modal. 我对python的了解不多,但是从我对您的问题的了解来看,您似乎想获得单击模态的表行。

If so, you can use some javascript to do that. 如果是这样,您可以使用一些JavaScript来做到这一点。 Add an onclick event to the table rows and pass the parameters you want in the modal: Eg onclick="setModalValues('1', 'John Doe') 将onclick事件添加到表行中,并在模式中传递所需的参数:例如onclick="setModalValues('1', 'John Doe')

<tr class="room" data-id="{{ res.room_id }}" data-toggle="modal" data-target="#orderModal"  onclick="setModalValues('1', 'John Doe')>

Write a javascript to set modal form input values on click. 编写JavaScript,以在点击时设置模式形式输入值。

<script type="text/javascript">
 function setModalValues(id, name) {
    $("#modalID").val(id);
    $("#modalName").val(name);
 }
</script>

In the modal you could have a form with the inputs fields like: 在模式中,您可以具有一个带有输入字段的表单,例如:

<input type="hidden" class="form-control" id="modalID"  name="modalID">

<div class="form-group">
   <label for="name">Name:</label>
   <input type="text" class="form-control" id="modalName" name="modalName">
</div>

Hope you can implement something similar in your case. 希望您可以针对您的情况实施类似的操作。

See a sample fiddle here 在这里查看样本小提琴

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM