我有一个以表单开头的页面。在该表单中,我呈现另一个名为信息的页面。在这个渲染中,我有另一个模态的渲染。这个模态是另一种形式。所以在这一点上,我有一个嵌套的形式。这在除了IE9之外的所有浏览器中都很好。我认为IE9试图做的是看到第二个表单何时结束,它也结束了第一个表单,所以嵌套表单之后的一切都被搞砸了。其他人遇到过这个问题吗?你是怎么解决的?
父文件(表单):
= simple_form_for @form do |f|
#the_form
= render 'information', :f => f
.buttons
%input{:name => "submit", :type => "submit", :value => "SUBMIT"}
%input{:name => "cancel", :type => "submit", :value => "Cancel"}
渲染信息文件:
#information
%fieldset
%legend
Form Title
= f.input :form_id, :url => form_name_path, :label => 'Field Name'
= render 'modal'
(the rest of the code here breaks)...
渲染模式文件:
.modal.hide.fade
.modalBox
%h3
New Form Name
%a{href: "#", class: "x", title: "Close" : 'data-dismiss' => "modal"}
.diagRepeater
.modal-body
= simple_form_for Form.new, :url => {:controller => :form, :action => :modal_create} do |o|
=o.input :name, :label => 'Name', :required => true
=o.input :form_id, :as => :hidden
我在最后一个文件中看到了问题。如果我在上注释掉simple_form_for,它将非常有效。如果我离开它,它将破坏表单的其余部分。
HTML不支持嵌套形式。一个页面中可以有多个表单,但它们不应该嵌套。正如你所说:这在所有浏览器中都很好,对我来说是奇迹,因为"你甚至会在同一浏览器的不同版本中遇到问题",所以避免使用它。
Webkit解释为什么HTML不支持嵌套形式
bool HTMLParser::formCreateErrorCheck(Token* t, RefPtr<Node>& result)
{
// Only create a new form if we're not already inside one.
// This is consistent with other browsers' behavior.
if (!m_currentFormElement) {
m_currentFormElement = new HTMLFormElement(formTag, m_document);
result = m_currentFormElement;
pCloserCreateErrorCheck(t, result);
}
return false;
}