【发布时间】:2014-02-16 15:56:33
【问题描述】:
我有以下代码来生成<form>
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
<h4 class="modal-title" id="myModalLabel">My form</h4>
</div>
<div class="modal-body">
<ul class="errors has-error"></ul>
<p>Some text</p>
<%= form_tag(some_path(@object), remote: true, id: "my-form") do %>
<table class="table table-striped show">
<tr>
<th></th>
<th>Some value</th>
<th>Some value2</th>
<th>Some value3</th>
<th>Some value4</th>
<th>Some value5</th>
<th>Some value6</th>
<th>Some value7</th>
</tr>
<% @object.each do |o| %>
<tr>
<td><div class="checkbox"><label><%= check_box :condition1, o.value1 %></label></div></td>
<td><%= o.value2.strftime("%d.%m.%Y") %></td>
<td><%= o.value3 %></td>
<td><%= o.value4 %></td>
<td><%= number_with_precision o.value5, :precision => 2 %></td>
<td><%= number_with_precision o.value6, :precision => 2 %></td>
<td><%= number_with_precision o.value7, :precision => 2 %></td>
<td><%= number_with_precision o.value8.strftime("%d.%m.%Y") %></td>
</tr>
<% end %>
</table>
<p>Some text.</p>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Cancel</button>
<%= submit_tag "Submit", data: { disable_with: "Please wait..." }, :id => 'modal-submit', :class => "btn btn-primary" %>
<% end %>
</div>
</div>
奇怪的是,在生成的 HTML 代码中,提交按钮放在 </form> 标记之后。但是,如果我在</table> 之后的第一个</div> 之前放置提交按钮,则<input class="btn btn-primary" data-disable-with="Please wait..." id="modal-submit" name="commit" type="submit" value="Submit"> 在表单内。这是预期的行为还是表单助手中的错误?
此代码有效
<p>Some text.</p>
<%= submit_tag "Submit", data: { disable_with: "Please wait..." }, :id => 'modal-submit', :class => "btn btn-primary" %>
<% end %>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Cancel</button>
</div>
</div>
编辑:这个问题似乎不是由 Rails 引起的。发送到浏览器的 HTML 代码实际上是正确的。但是浏览器过早地关闭了表单。因此这一定是无效的 HTML,但我不知道为什么。
【问题讨论】:
标签: html ruby-on-rails ruby-on-rails-4