Form Submit button only works after reload

前端 未结 6 1350

I have an index page that builds a table, and I am trying to allow users to edit line\'s in the table. I am trying to do this in the most basic way possible - no javascript

相关标签:
6条回答
  • 2020-11-29 09:39

    Try putting data-no-turbolink="true" into the link that called the table page.

     <a href="/vender" data-no-turbolink="true">
    

    That works form me.

    0 讨论(0)
  • 2020-11-29 09:41

    This type of error is most frequently one generated by invalid HTML. Various sources of errors can be:

    • missing < or >
    • HTML tag not closed
    • orphaned HTML closing tag (where no opening one is related); in complex forms I've had extra </div>s lying about...
    • Forms nested within table or tr tags (within td is allowed)

    The form helpers need to be properly nested, otherwise these quirks will bite you...

    0 讨论(0)
  • I believe this is an HTML issue, not a Rails issue. Per this discussion Form inside a table, <form> can not be placed inside <table> or <tbody> or <tr>. After moving the <form> to wrap the table and putting the controls inside the respective <td> the form works.

    I still don't understand why refreshing the page made the form work, but...

    0 讨论(0)
  • 2020-11-29 09:53

    If it's Rails 4, it's probably because of Turbolinks. Try putting

    data-no-turbolink="true" inside your body tag
    

    This may work, it happend once to me.

    0 讨论(0)
  • 2020-11-29 09:53

    For rails 5, try using data: { turbolinks: false } inside any links to the page containing the form.

    E.g. <%= link_to "Get in Touch", 'contact', data: { turbolinks: false } %>

    0 讨论(0)
  • 2020-11-29 09:59

    I have to share my experience : I played with Turbolinks, like you. But suddently, I had an issue : the previous pages needed to have turbolinks disabled too, to work. After many & many & many hours on the issue, I found the solution : <% f.submit %> was separated by 2 <div>from the rest of the form ! Here is an example: Wrong:

    <div class="container">
        <div class="row">
            <!-- Inscription -->
            <div class="col-lg-8 contact_col">
                <div class="get_in_touch">
                    <div class="section_title">Modifier une marque</div>
                    <div class="contact_form_container">
                        <%= form_for @brand, url: {action: "update"} do |f| %>
                        <div class="row">
                            <div class="col-xl-12">
                                <!-- Name -->
                                <label for="contact_name">Nom de la marque</label>
                                <%= f.text_field :brand, class: "contact_input" %>
                            </div>
                            <div class="col-xl-12 last_name_col">
                                <span>
                                    <%= f.label "Image de la marque" %><br />
                                </span>
                                <%= f.file_field :brand_picture %>
                            </div>
                        </div>
                    </div>
                </div>
                <button class="newsletter_button trans_200">
                    <%= f.submit "Modifier" %>
                </button>
                <% end %>
            </div>
        </div>
    </div>
    

    Correct:

       <div class="container">
        <div class="row">
            <!-- Inscription -->
            <div class="col-lg-8 contact_col">
                <div class="get_in_touch">
                    <div class="section_title">Modifier une marque</div>
                    <div class="contact_form_container">
                        <%= form_for @brand, url: {action: "update"} do |f| %>
                        <div class="row">
                            <div class="col-xl-12">
                                <!-- Name -->
                                <label for="contact_name">Nom de la marque</label>
                                <%= f.text_field :brand, class: "contact_input" %>
                            </div>
                            <div class="col-xl-12 last_name_col">
                                <span>
                                    <%= f.label "Image de la marque" %><br />
                                </span>
                                <%= f.file_field :brand_picture %>
                            </div>
                        </div>
                        <button class="newsletter_button trans_200">
                            <%= f.submit "Modifier" %>
                        </button>
                        <% end %>
                    </div>
                </div>
            </div>
        </div>
    </div>
    
    0 讨论(0)
提交回复
热议问题