turbolinks / turbolinks-classic

Classic version of Turbolinks. Now deprecated in favor of Turbolinks 5.
MIT License
3.54k stars 431 forks source link

Turbolinks 3 (and older) onclick on tr of a table can't trigger click if link isn't "remote: true" #566

Closed ghost closed 9 years ago

ghost commented 9 years ago

I have these code:

In application.js:

    $(document).on('click', 'tr[data-link]', function(e) {
        if($(e.target).closest('a').length) return;
        var puls = $('a#trClick', $(this).closest('tr').children('td'));
        puls.trigger('click');
    });

In my template.html.erb I have:

    <tr data-link="<%= element_path(element) %>">
      <td>
        <%= link_to 'Wow', element, id: 'trClick', remote: true %>
      </td>
    </tr>

If I remove from this link_to the remote: true tag, the click can't get triggered and the click on tr makes no effect. Why?

So I put this code in my application.js to make it works, but I think it is a mess:

    $(document).on('click', 'tr[data-link]', function(e) {
        if($(e.target).closest('a').length) return;
        var puls = $('a#trClick', $(this).closest('tr').children('td'))

        if(puls.data("remote") == true) {
          puls.trigger('click');
        } else {
          Turbolinks.visit(this.dataset.link);
        }
    });

HOW TO FIX?

Thibaut commented 9 years ago

This doesn't seem to be an issue with Turbolinks. Please ask on StackOverflow, or provide a test case to reproduce the issue.

ghost commented 9 years ago

I think is a problem with Turbolinks. Anyway, thanks. :dancers:

http://stackoverflow.com/questions/31251951/turbolinks-3-and-older-onclick-on-tr-of-a-table-cant-trigger-click-if-link-is

MrHubble commented 8 years ago

@ginolon your StackOverflow question no longer exists. Did you find a solution to your onclick problem? I'm also using Turbolinks.visit(link); on row click and the GET request is being called twice.

UPDATE: my issue was with my own messy js, not Turbolinks.

maltesa commented 8 years ago

I have the same issue. Turbolinks and remote forms work fine together as long as the remote form is not wrapped around a table row.

This only works, after refreshing the page. Otherwise no post is made.

[...]
%tr.course-day{ id: "course_day_#{course_day.id}" }
  = simple_form_for course_day, remote: true do |f|
    %td
      = f.input_field :day, as: :date_picker, placeholder: "01.01.2000"
[...]

Update: It's already not working as long as the form is within a table.