【发布时间】:2014-04-29 22:14:28
【问题描述】:
我的页面通过 jQuery 将表单呈现为 html。有时,当我单击提交或按 Enter 时,按钮变为“加载”状态但表单未提交,服务器或网络选项卡上没有任何反应,用户必须重新加载页面才能尝试提交再次形成。因此,我从表单中删除了按钮并将其放置在之后,并更改了 jQuery,以便在单击此按钮时也提交表单。这工作正常,但用户现在无法单击 Enter 提交表单,这是我的客户的一个重要用例。有谁知道原始问题或潜在修复的原因可能是什么?谢谢!
新的 jQuery
$("#add_order_btn").click(function(){
$(this).button('loading');
$("#new_order").submit(); # added as fix when button moved outside the form
});
新表格
<%= form_for(@new_order, url: add_order_url, method: "post", remote: true, class: "form-inline mb0") do |f| %>
<%= f.text_field :order_start_date_time, class: "new-order-datetime input-medium", placeholder: "Start date & time", id:"new_order_time" %>
<%= f.text_field :yrd, placeholder: "# of yards", class: "span2" %>
<%= f.check_box :plus %>
<%= f.label :plus, '<i class="fa fa-plus" id="go_plus"> </i>'.html_safe, class: "label_inline mr15" %>
<%= f.text_area :notes, placeholder: "Private Dispatch notes", class: "span12", id: "new_text_area", rows: "1" %>
<h4 class="mt5" id="new_order_extras">Order extras
<%= link_to "Add", new_order_extras_url, remote: true %>
</h4>
<% end %>
<%= button_tag '<i class="fa fa-list-alt"></i> New Order'.html_safe, class: "btn btn-primary btn-block btn-large mt5 mb15", id: "add_order_btn" %> # Moved out of form as fix
【问题讨论】:
-
你能做一个jsfiddle的例子吗?
标签: javascript jquery forms ruby-on-rails-4 twitter-bootstrap-2