Search code examples
ruby-on-railsruby-on-rails-3internet-explorerhamlsimple-form-for

IE9 nested simple_form_for with haml


I have a page That starts with a form. Inside that form, I render another page called information. Inside this render I have another render for a modal. This modal is another form. So at this point i have one nested form. This works great in all browsers except IE9. I think what IE9 is trying to do is it sees when the second form is ending, and it also ends the first form, so everything that is after the nested form is screwed up. Has anyone else ran into this problem? and how do you fix it?

Parent File (form):

= 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"}

Render information file:

#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)...

Render modal file:

.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

It is in this last file that I see the problem. If I comment out the simple_form_for and on, it will work great. If I leave it, it will break the rest of the form.


Solution

  • HTML not support nested form. You can have several forms in a page but they should not be nested. As you say: this work great in all browser for me it is miracle because 'You would even have problems making it work in different versions of the same browser' so avoid using that.

    Webkit explain why HTML not supporting nested form

    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;
    }