< DIV>打破< form> [英] <div> breaks <form>

查看:117
本文介绍了< DIV>打破< form>的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下代码来生成< form>

  <div class="modal-dialog">
<div class="modal-content">
  <div class="modal-header">
    <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</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> code>< input class =btn btn-primarydata-disable-with =Please wait ...id =modal-submitname =committype =submitvalue =Submit > 在表单内。这是预期行为还是形式助手中的错误?

Oddly, in the generated HTML code the submit button is put after the </form> tag. However, if I place the submit button before the first </div> after </table>, <input class="btn btn-primary" data-disable-with="Please wait..." id="modal-submit" name="commit" type="submit" value="Submit"> is within the form. Is this intended behaviour or a bug in the form helper?

此代码有效

    <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,但我不知道为什么。

This problem doesn't seem to be caused by Rails. The HTML code that gets send to the browser is actually correct. But the browser closes the form too early. This must therefore be invalid HTML, but I have no idea why.

推荐答案

显然,您不允许在< div> ,无需关闭标签前的表单。我在< div class =modal-body> < form> 标签,解决了我的问题>

Apparently you are not allowed to start a form within a <div> without closing the form before the tag. I solved my problem by placing the <form> tag before <div class="modal-body">

这篇关于&LT; DIV&GT;打破&lt; form&gt;的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆