Problem/Motivation

In upgrading a site to use a release of jQuery newer than 1.5, the dependent checkbox code fails with a trigger value of one or true. This is because, in the ctools 1.2 release (used on the site), the dependent.js code uses the attr() function as the value of this property in:
var val = $(trigger).attr('checked') || 0;
which changed from returning true to 'checked' with the 1.6 release. This code changed in the ctools 1.3 release to:
var val = $(trigger).attr('checked') ? true : false;

Per the jQuery documentation, the property value is the preferred item to use with a checkbox element. The return value of prop() did not change with the 1.6 release.

Proposed resolution

Use the prop() function in dependent.js to determine whether the element is checked. Given the change in the 1.3 release (for returning true or false, and not 'checked' or 0 which would be the case without the change shown above), the current proposed change should have no adverse consequences on existing code. Any site using the 1.2 release of dependent.js with a 1.6+ release of jQuery would have had to modify its code to use a trigger value of 'checked' to deal with the change in return value, and would have to revert it with the next release of ctools.

Remaining tasks

Review, test, document.

User interface changes

None.

API changes

None.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

solotandem’s picture

Issue summary: View changes
solotandem’s picture

Issue summary: View changes
solotandem’s picture

Status: Active » Needs review
FileSize
870 bytes

Attached patch implements proposed resolution.

solotandem’s picture

Issue summary: View changes
tien.xuan.vo’s picture

#1494860-3: Views Rewrite Results UI Broken using JQuery 1.7 Already has a patch that work well for me, but it is not committed. I have re-rolled the patch.

solotandem’s picture

If you are rerolling a patch on another issue, then why not post it on that issue?

tien.xuan.vo’s picture

I thought about that, but that issue is fixed and committed. This is a issue related to that issue, so I think here is the best place to upload the patch.

andeersg’s picture

Status: Needs review » Reviewed & tested by the community

I can verify that the patch in #5 works, tested it with CTools 7.x-1.9 and Panels 7.x-3.5 (Tested the panel pane override title form).

IRuslan’s picture

Also works for me.
Tested with jQuery 1.10.

MustangGB’s picture

Title: Use checked property in dependent.js » Checkbox triggered dependent form items broken for jQuery 1.7+
Priority: Normal » Major
Issue tags: +DrupalWTF

Works great with jQuery 2.1

japerry’s picture

Status: Reviewed & tested by the community » Fixed
Issue tags: -DrupalWTF

Thanks for the patch!

This tested out for me in both stock jquery as well as an updated (1.10) version. Committed.

  • japerry committed 1838542 on 7.x-1.x authored by tien.xuan.vo
    Issue #2353853 by solotandem, tien.xuan.vo: Checkbox triggered dependent...

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.