Lighthouse has a new layout. Prefer the old one? Return to the old layout, and switch back any time from the link at the top of each page.

This project is archived and is in readonly mode.

:disable_with option doesn't work inside a <table> tag

#4723

As in the title.

Steps to reproduce:
Create a form with a submit including a :disable_with => "Something" option - it works.
Now wrap the form in a

tag and try it out again - it doesn't disable the button anymore.

This doesn't happen for the :confirm option.

I'm using edge Rails 3 on 64-bit Gentoo Linux

Reported by The_Lord · May 29th, 2010 @ 12:51 PM

State: invalid
Milestone: 3.1
Assigned to: Yehuda Katz (wycats) Yehuda Katz (wycats)
Importance: Low

Activity

  1. Shih-gian Lee
    Shih-gian Lee

    Confirmed that when wrapping a table tag around a form, :disable_with does not work.

    <table>
     <%= form_for(@product) do |f| %>
       ...
       <div class="actions">
        <%= f.submit :disable_with => "Processing ..." %>
      </div>
     <% end %>
    </table>
    

    May 29th, 2010 @ 02:39 PM

  2. Shih-gian Lee
    Shih-gian Lee

    However, when wrapping a form around a table, :disable_with works.

     <%= form_for(@product) do |f| %>
       <table>
          ...
          <div class="actions">
            <%= f.submit :disable_with => "Processing ..." %>
          </div>
       </table>
     <% end %>
    

    May 29th, 2010 @ 03:04 PM

  3. The_Lord
    The_Lord

    Yeah, but my form is a partial (I use it just to generate this button, because button_to doesn't take the :disable_with option) and if I wrap just the content of the form in this tag it doesn't look that pretty. The whole form needs to be wrapped. Besides it is a bug anyway I think ;) I can live with it, but it should be fixed just as any other bug. Thanks for trying to come up with a workaround, but it ain't what I need.

    May 29th, 2010 @ 05:14 PM

  4. Neeraj Singh
    Neeraj Singh

    What JavaScript library is being used?

    May 29th, 2010 @ 06:41 PM

  5. The_Lord
    The_Lord

    <%= javascript_include_tag :defaults %>

    I don't know exactly which library is it based on.

    May 29th, 2010 @ 10:26 PM

  6. Shih-gian Lee
    Shih-gian Lee

    Correction on my previous example. I got lazy and didn't construct a well-formed html in my example. The form works in a table tag:

    <table>
      <tr>
        <td>
            <%= form_for(@product) do |f| %>
              ...
              <div class="actions">
                <%= f.submit :disable_with => "Processing ..." %>
              </div>
            <% end %>
            </td>
        </tr>
    </table>
    
    The JavaScript library used is rails.js, which is the default js library.
    
    Can you share some snippets of your code here?
    

    May 30th, 2010 @ 02:25 AM

  7. The_Lord
    The_Lord

    Well your example works, but it still doesn't look like what I need since inside the td tag my styling stops working (float: right; to be exact) and I need to wrap the content of the form in an additional tr tag, which again breaks the :disable_with option. My code is practically identical to the example you provided, except I use a small tag instead of div and have additional label for the submit button. Both the label and the value of the button are assigned by the I18n::t method, but I doubt it is relevant.

    <table>
      <tr>
        <td>
          <%= form_for :book, :url => { :action => :publish, :id => book.id } do |form| %>
            <small class="right"><%= book.published == true ? t(:published) : t(:not_published) %>
            <%= form.submit book.published == true ? t(:hide) : t(:publish), :disable_with => t(:please_wait), :confirm => t(:are_you_sure?) %></small>
          <% end %>
        </td>
      </tr>
    </table>
    

    In this example it works, but doesn't take the class="right" into account so it doesn't look quite as I would want it to. If you wrap the content of the form, as I said before, in an additional tr it breaks the disable_with again.

    May 30th, 2010 @ 02:56 AM

  8. Aaron Patterson
    Aaron Patterson
    • Assigned user changed from Aaron Patterson to Yehuda Katz (wycats)

    I think Yehuda might know how to fix this better than me.

    June 25th, 2010 @ 11:58 PM

  9. Yehuda Katz (wycats)
    Yehuda Katz (wycats)

    Are you using the Prototype rails.js or the jQuery one?

    June 26th, 2010 @ 12:02 AM

  10. The_Lord
    The_Lord

    I used the standard libraries provided by rails 3.0.0.beta3 generator so I guess it's Prototype.

    June 26th, 2010 @ 12:05 AM

  11. Santiago Pastorino
    Santiago Pastorino
    • State changed from new to open
    • Tag changed from rails 3.0.0.beta3, disable_with, table to rails 300beta3, disable_with, table
    • Importance changed from to Low

    This issue has been automatically marked as stale because it has not been commented on for at least three months.

    The resources of the Rails core team are limited, and so we are asking for your help. If you can still reproduce this error on the 3-0-stable branch or on master, please reply with all of the information you have about it and add "[state:open]" to your comment. This will reopen the ticket for review. Likewise, if you feel that this is a very important feature for Rails to include, please reply with your explanation so we can consider it.

    Thank you for all your contributions, and we hope you will understand this step to focus our efforts where they are most helpful.

    February 2nd, 2011 @ 05:01 PM

  12. Santiago Pastorino
    Santiago Pastorino
    • State changed from open to stale

    February 2nd, 2011 @ 05:01 PM

  13. The_Lord
    The_Lord

    Well I can confirm that the issue still exists on master. It doesn't work with neither Prototype, nor Jquery (via the jquery-rails gem). However despite trying it on master and digging through the code a little I still haven't been able to locate the problem. It's strange that it doesn't work for both Prototype and Jquery. Could this be an issue with JavaScript in general handling the table tag? It certainly isn't browser-specific as I tried it on Chromium, Firefox, Opera, Epiphany and Links ;].

    I have to admit that my skills currently aren't sufficient to research this any further.

    Since it isn't that big an issue I think it can remain stale until someone wiser than me runs out of more important ones. Cheers and keep up the great work Rails Team! :)

    February 9th, 2011 @ 12:50 AM

  14. Santiago Pastorino
    Santiago Pastorino
    • State changed from stale to open
    • Milestone set to 3.1

    February 9th, 2011 @ 02:19 AM

  15. Jonah Burke
    Jonah Burke

    I looked into this issue, and I don't think it's a bug. As Shih-gian points out, the submit button fails to dim only when the form is not within a td (e.g. when the form is a child of the table). This is invalid HTML. The reported behavior is a result of how Gecko and WebKit parse this invalid HTML. They move the input outside the form (and the table), so when disableFormElements in rails.js (either version) looks at the form, there are no inputs to disable.

    For example, the following markup

    yields the following DOM:

    input
    table
    form

    I can't imagine why anybody would want to use this markup. It's invalid, and if you really want the input outside the table (but why would you?), just put it there. This bug should be resolved by design.

    February 26th, 2011 @ 03:28 AM

  16. Jonah Burke
    Jonah Burke

    Whoops, here's another try, with proper formatting:

    I looked into this issue, and I don't think it's a bug. As Shih-gian points out, the submit button fails to dim only when the form is not within a td (e.g. when the form is a child of the table). This is invalid HTML. The reported behavior is a result of how Gecko and WebKit parse this invalid HTML. They move the input outside the form (and the table), so when disableFormElements in rails.js (either version) looks at the form, there are no inputs to disable.

    For example, the following markup

    <table>
      <form>
        <input/>
      </form>
    </table>
    

    yields the following DOM:

    input
    table
      form
    

    I can't imagine why anybody would want to use this markup. It's invalid, and if you really want the input outside the table (but why would you?), just put it there. This bug should be resolved by design.

    February 26th, 2011 @ 03:30 AM

  17. The_Lord
    The_Lord

    That's true. I was young and too stupid to use HTML validators when I filed this. Please mark this as invalid and call me 'idiot'. Sorry :/

    February 26th, 2011 @ 09:56 PM

  18. Santiago Pastorino
    Santiago Pastorino
    • State changed from open to invalid

    February 27th, 2011 @ 04:01 AM

  19. bingbing