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.

jquery-ujs rails.js doesn't work with jQuery 1.4.3

#5840

There's a problem regarding the data-confirm attribute.
If you add the :confirm option to a link, it is always submitted regardless you confirm or not the dialog.

Reported by Simone Carletti · October 19th, 2010 @ 02:34 PM

State: resolved
Milestone: 3.1
Assigned to: Santiago Pastorino Santiago Pastorino
Importance: High

Activity

  1. Jon Buda
    Jon Buda

    Seeing this as well. I'm thinking it's due to the way 1.4.3 now handles the html data attributes.

    October 19th, 2010 @ 03:29 PM

  2. Neeraj Singh
    Neeraj Singh
    • Importance changed from to Low

    Looking into it.

    October 19th, 2010 @ 03:59 PM

  3. Simone Carletti
    Simone Carletti

    Honestly, I would increase the priority.
    If you upgrade to jQuery 1.4.3 and you use :confirm on a delete action, the record will be delete no matter if you click on cancel...

    October 19th, 2010 @ 04:01 PM

  4. Neeraj Singh
    Neeraj Singh
    • Importance changed from Low to High

    Bumped up the priority.

    Not sure why but two tests are failing for jquery 1.4.2 . Last time I checked in my code all the tests were passing. Oh well. First I am looking a fix for jquery 1.4.3 and then will fix the tests. Such is life :-)

    October 19th, 2010 @ 04:22 PM

  5. Neeraj Singh
    Neeraj Singh

    Update:

    In jQuery 1.4.3 "returning false" does not mean that rest of live bindings will not be called.

    http://jsbin.com/ehagi4/2/edit

    http://jsbin.com/ehagi4/3/edit

    I am trying to get a confirmation from jQuery team if that is intentional ( most likely it is) or if it is a bug.

    In the meantime I would suggest not to upgrade to jQuery 1.4.3 least of which is because of rails.js. This feature of going through all live bindings potentially can break a lot of things in your app. :-)

    October 19th, 2010 @ 05:19 PM

  6. Santiago Pastorino
    Santiago Pastorino
    • State changed from new to open
    • Milestone set to 3.1
    • Assigned user set to Santiago Pastorino

    October 19th, 2010 @ 05:22 PM

  7. Neeraj Singh
    Neeraj Singh
    • State changed from open to new
    • Milestone cleared.
    • Assigned user cleared.

    Here is link to the email sent to jQuery core mailing list.

    http://forum.jquery.com/topic/in-jquery-1-4-3-event-after-returning...

    October 19th, 2010 @ 05:30 PM

  8. Santiago Pastorino
    Santiago Pastorino
    • State changed from new to open
    • Milestone set to 3.1
    • Assigned user set to Santiago Pastorino

    October 19th, 2010 @ 08:12 PM

  9. Yuval Kordov
    Yuval Kordov

    We've temporarily resolved this issue by replacing the live call with a delegate:

    // $('a[data-confirm],input[data-confirm]').live('click', function () { ... $('body').delegate('a[data-confirm],input[data-confirm]','click', function(e) { ...

    October 19th, 2010 @ 10:08 PM

  10. Yuval Kordov
    Yuval Kordov

    Let's try that again:

    // $('a[data-confirm],input[data-confirm]').live('click', function () { ... $('body').delegate('a[data-confirm],input[data-confirm]','click', function(e) { ...

    October 19th, 2010 @ 10:09 PM

  11. Yuval Kordov
    Yuval Kordov

    I hate markdown.

    // $('a[data-confirm],input[data-confirm]').live('click', function () { ...
    $('body').delegate('a[data-confirm],input[data-confirm]','click', function(e) { ...
    

    October 19th, 2010 @ 10:10 PM

  12. Neeraj Singh
    Neeraj Singh

    @Yuval That works.

    I am still awaiting to hear from jQuery core team regarding official statement. As per http://jsbin.com/ehagi4/4/edit looks like using delegate works as jQuery 1.4.2 works with live with respect to not continuting with the call chain once 'return false' has been invoked.

    delegate was introduced in jQuery 1.4.2. If rails.js starts using that then people will not be able to use jQuery 1.4.1.

    I will wait for the official statement from jQuery team and then we will try to find a solution.

    October 19th, 2010 @ 10:50 PM

  13. Matheus Cáceres
    Matheus Cáceres

    I use JQuery 1.4.3 and Jquery-ujs today and here that's ok.
    Maybe issue its fixed.

    November 6th, 2010 @ 04:05 AM

  14. Neeraj Singh
    Neeraj Singh
    • State changed from open to resolved

    Closing this ticket since the issue is fixed.

    November 6th, 2010 @ 07:01 AM

  15. Greg B
    Greg B

    I'm still seeing this problem with 3.03, jquery 1.4.4, and the latest rails.js from https://github.com/rails/jquery-ujs/blob/master/src/rails.js.

    http://bugs.jquery.com/ticket/7217 seems to be the relevant jquery bug but is fixed in 1.4.4.

    November 17th, 2010 @ 05:15 PM

  16. Greg B
  17. Neeraj Singh
    Neeraj Singh

    That is why in the current version of rail.js confirmation is bound to body and not to document. https://github.com/rails/jquery-ujs/blob/master/src/rails.js#L80

    Can you describe what is the issue you are running into with rails.js ?

    November 17th, 2010 @ 09:08 PM

  18. Greg B
    Greg B

    I have a simple Delete link as follows
    <%= link_to 'Destroy', @report, :confirm => 'Are you sure?', :method => :delete %>

    When I click on it, it gives me the confirmation pop-up and if I click "Cancel", it repeats the pop-up one more times and then still deletes the record and tries to show the deleted record (does a GET "report/:id" request)

    November 17th, 2010 @ 11:51 PM

  19. Neeraj Singh
    Neeraj Singh

    Just now I tested with

    rails edge
    jQuery 1.4.4
    railsj.js current version

    when I click on cacel nothing happens. There is no repetition.

    I tested with FF, safari and chrome.

    November 18th, 2010 @ 12:17 AM

  20. Greg B
    Greg B

    Ok, I tried again using a skeletal app and everything works fine. I isolated the problem to trying to use ujs with the jquery-colorbox plugin in my original app.

    Sorry for the confusion

    November 18th, 2010 @ 01:34 AM