Rails 3 中其他远程表单内的远程表单禁用嵌套表单
我所拥有的是另一个 remote
表单中的 remote
表单,如下所示:
<%=form_for @myobj,:as=>:myobj,:url=>{:controller=>"my_controller",:action=>"first_action"},:remote=>true do |f|%>
<%=form_for @myotherobj,:as=>:myotherobj,:url=>{:controller=>"my_controller",:action=>"second_action"},:remote=>true do |ff|%>
<%=ff.submit "second"%>
<%end%>
<%=f.submit "first"%>
<%end%>
但是然后我单击第二个提交,它不会执行远程调用,它会执行正常调用导致我出现错误Missing Template
,因为我的操作仅响应JS
(Ajax 调用)
What I have is a remote
form inside another remote
form like this:
<%=form_for @myobj,:as=>:myobj,:url=>{:controller=>"my_controller",:action=>"first_action"},:remote=>true do |f|%>
<%=form_for @myotherobj,:as=>:myotherobj,:url=>{:controller=>"my_controller",:action=>"second_action"},:remote=>true do |ff|%>
<%=ff.submit "second"%>
<%end%>
<%=f.submit "first"%>
<%end%>
But then I click the second submit it doesn't do a remote call, It does a normal call with leads me to an error Missing Template
because my action only responds to JS
(Ajax Calls)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
嵌套表单是无效的 html。
浏览器的行为未定义在这种情况下该怎么做。这就像尝试在 html 文档中多次使用 ID 一样。它通常是由 document.getElementById 选择的最早出现的 ID,在这里您会发现最外层(最早)的表单就是正在提交的表单。
如果(至少)其中一个表单是使用 JavaScript 提交的,那么最好在其他地方创建表单并复制值,或者在提交之前移动表单元素。
Nested forms are invalid html.
The browsers behaviour is undefined what to do in such a case. It's just like trying to use IDs multiple times inside a html document. It will normally be the earliest occurrence of the ID that will be selected by a document.getElementById, and here you are finding the outermost (earliest) form is the one that is submitting.
If (at least) one of the forms is being submitted with javascript, then it would probably be better to create the form elsewhere and copy the values, or move the form elements prior to submitting.