Many sites now use various means to update their version of jQuery to a later version than 1.4, the version in Drupal 7.
jQuery deprecated (version 1.6) and removed (version 1.9) the use of .attr()
for use to set "checked" and "disabled" properties. It also points out that attempting to retrieve values by using .attr()
will result in confusion/problems, as in this example: $elem.attr("checked");
will return true if $elem
has a "checked" property at all, not if it is true.
jQuery now uses .prop()
instead to set and retrieve the value of a "checked" or "disabled" properties of a node.
.removeAttr() may also cause problems/unexpected behavior, as it completely removes the property rather than setting it to false, consequently it will no longer be selectable by selectors that typically would work.
Example:
Using <code>jQuery('input[name="test"]').removeAttr('checked');
on <input name="test" type="checkbox" checked="true" />
will result in <input name="test" type="checkbox" />
. This is typically not the intended result, as it will cause CSS and jQuery selectors that you would expect to be able to find that item to fail.
Example: jQuery('input[checked]')
will now fail to return this node.
See: jQuery 1.9 Upgrade Guide: attr vs. prop
It looks like the jQuery Update module's newest dev branch (7.x-3.x-dev) is including an option via a patch for using jQuery Migrate, which fixes compatibility with legacy jQuery code in newer version of jQuery. However, since most users will not move to that branch until it is out of dev, either a dependency on certain versions of jQuery and possibly certain settings in jQuery update need to be addressed, or the code in question should be made to work with all versions of jQuery.
Possible problems:
file: ctools/js/dependent.js
- Line 100:
var val = $(trigger).attr('checked') ? true : false;
- Line 169:
object.attr('disabled', false);
- Line 171:
object.children().attr('disabled', false);
- Line 177:
object.attr('disabled', true);
- Line 178:
object.children().attr('disabled', true);
file: ctools/js/stylizer.js
- Line 216:
$widget.attr('checked', !$widget.attr('checked') || $widget.is('input[type=radio]'));
- Line 216:
$widget.attr('checked', !$widget.attr('checked') || $widget.is('input[type=radio]'));
Comment | File | Size | Author |
---|---|---|---|
#5 | ctools-jquery-attr-removed-2416689-5.patch | 2.38 KB | jacktonkin |
Comments
Comment #1
DrCord CreditAttribution: DrCord commentedComment #2
mrjmd CreditAttribution: mrjmd commentedI'm curious how other modules are handling this.
Here's an attempt at a patch that checks jquery version and responds accordingly. Not sure how helpful it will be but it's a start. This patch also assumes 1.x, I see there is already an issue in the jquery update queue bout allowing 2.0 here: #1974482: Offer latest jQuery 2.x as an option (currently 2.1.0) - Fall back to 1.x for IE6/7/8..
Comment #3
DrCord CreditAttribution: DrCord commentedThere seem to be a few ways of going about this:
My first inclination is that #4 or #5 sound the most feasible.
There could be additional options or combinations of these that are better, I am just trying to help the discussion get started and once we have a viable solution, potentially help roll patches.
Comment #4
jacktonkin CreditAttribution: jacktonkin commentedAnother alternative is to use the DOM checked & disabled properties directly.
The attached patch does just this. Where it's obvious that there should only be one matched element I've explicitly set the first, rather than iterating over the set with
.each()
. For getters.attr()
returned the value from the first matched element anyway.Comment #5
jacktonkin CreditAttribution: jacktonkin commentedThe previous patch wrongly imagined jQuery's
.not()
returned a boolean. It doesn't, of course. Please review the attached patch.Comment #6
mglamanCouldn't this be simplified to just
$(trigger).is(':checked');
Accessing items within the jQuery object directly doesn't feel like the appropriate approach either. There should be a method which will be supported across the different versions.
Comment #7
Anonymous (not verified) CreditAttribution: Anonymous commentedThe patch is working great for me.
Does it accomplish its task in the 'best' way possible? Maybe not.
I'd like to see it get as soon as possible, as it fixes a bug many people are experiencing.
If it needs a little refactoring, can that happen on a re-visit?
Comment #8
sylus CreditAttribution: sylus commentedThe patch no longer applies as of ctools 1.10 and I think might be superceded?
#2353853: Checkbox triggered dependent form items broken for jQuery 1.7+
Comment #9
rudiedirkx CreditAttribution: rudiedirkx at ezCompany commentedFixed in #2353853: Checkbox triggered dependent form items broken for jQuery 1.7+:
Was in 1.10.