我有以下代码来生成<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>
标记之后。但是,如果我在</div>
之后的第一个</table>
之前放置提交按钮,则<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,但我不知道为什么。
答案 0 :(得分:2)
显然,您不能在<div>
内启动表单,而不会在标记之前关闭表单。我通过在<form>
<div class="modal-body">
标记解决了我的问题
答案 1 :(得分:0)
选择cate从哪里开始表格以及在哪里完成。这有用吗?
<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>
<%= form_tag(some_path(@object), remote: true, id: "my-form") do %>
<div class="modal-body">
<ul class="errors has-error"></ul>
<p>Some text</p>
<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" %>
</div>
<% end %>