我正试图在rails表单中的modal中加载支付表单。现在,当我单击"立即购买"时,modal将加载,但表单将提交。我怎么能让它不提交,直到有人在模态中点击"提交"。
= form_tag foo_path, id: 'payment-form' do
-if @store.products == nil
Test
- @store.products.each_with_index do |product, index|
.row
.col-lg-2
- if current_user
- if store.user_id == current_user.id
= link_to "Delete", product_path(product), data: { method: "delete", confirm: "Are you sure?"}
.col-lg-8
.panel.panel-default
.panel-body
.row
.col-lg-2
%input{:type => "checkbox", :id => "switchName#{index}", :class => "check"}/
%label{:for => "switchName#{index}"}
.col-lg-8
= hidden_field_tag("order_products[][product_id]", product.id)
= product.name
%br
.subheader= number_to_currency(product.cost_in_cents.to_f / 100)
.col-lg-2
= select_tag("order_products[][quanity]", options_for_select([0,1,2,3,4,5,7,8,9,10,11,12,13,14,15]), "data-cost-per-unit" => product.cost_in_cents, id: product.name, class: "drop", :prodindex => index)
.col-lg-2
-if current_user
-else
%span.payment-errors
.text-center
%h2.total-amount
Total:
$0.00
%hr
.text-center
%button.btn.btn-primary.btn-lg{"data-target" => "#myModal", "data-toggle" => "modal"}
Buy Now
默认情况下,单击<button>
元素时,会提交包含表单:source。
如果你在创建按钮时使用{"data-target" => "#myModal", "data-toggle" => "modal", "type" => "button"}
,它应该在不提交表单的情况下显示你的模态
然后,如果你想这样做的话,你就必须在模态中处理提交表单的问题。