Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
Problem/Motivation
Convert state-based selectors to be compatible with with jQuery native-API selector
Proposed resolution
Follow this replacement pattern:
$('selector:hidden') -> $('selector').filter(':hidden')
$('selector:slected') -> $('selector').filter(':selected')
$('selector:visible') -> $('selector').filter(':visible')
$('selector:animated') -> $('selector').filter(':animated')
Comments
Comment #1
tarekdj CreditAttribution: tarekdj commentedComment #2
InternetDevels CreditAttribution: InternetDevels commentedSeems changed
Comment #3
mathes CreditAttribution: mathes commentedyep seems changed.
Comment #4
mathes CreditAttribution: mathes commentedComment #5
nod_Tested as well, RTBC +1
Comment #6
droplet CreditAttribution: droplet commentedpreferred to use eq()?? Please drop it. https://drupal.org/comment/8364645#comment-8364645
:not -> .not ?
Comment #7
nod_:not is CSS3 nous problem with that
Comment #8
nod_The :not in selector is fine, but the first point of droplet comment still stands. Better to use .eq().
When re-rolling you should know that the indentation standard changed for JavaScript files.
Comment #9
nod_Rerolled the patch, Comments still needs to be addressed but at least patch applies.
Comment #10
InternetDevels CreditAttribution: InternetDevels commentedSomething like this?
Comment #11
nod_yeah, seems like I added some whitespace things during my reroll. :/ i'll have to get rid of them.
Comment #12
droplet CreditAttribution: droplet commenteddrop this change we need not reroll second time on other issue. ( https://drupal.org/comment/8364645#comment-8364645 )
Comment #15
ahemnell CreditAttribution: ahemnell commentedPatch re-rolled.
Comment #16
rteijeiro CreditAttribution: rteijeiro at Tieto commentedI checked responsive tables, ajax autocomplete and table drag and everything seems to work well so this looks like RTBC.
Comment #17
nod_Comment #18
rteijeiro CreditAttribution: rteijeiro at Tieto commentedThanks for the review @nod_. I was using jslint for code check :(
Comment #19
ahemnell CreditAttribution: ahemnell as a volunteer commentedYou beat me to it Ruben :) Here is a new patch with your fixes but without those speces after named js functions as stated in https://www.drupal.org/node/172169#functions
Comment #20
droplet CreditAttribution: droplet commentedI don't know if we should do it at once. No leading ">" allowed. It should converted to $.children().
Thanks.
Comment #21
rteijeiro CreditAttribution: rteijeiro at Tieto commentedThanks for your patch @ahemnell. We didn't have the chance to discuss about interdiffs (difference between your patch and the previous patch). It's a good practice to provide them as you can see in #18. Let me know if you need help creating one ;)
Comment #22
ahemnell CreditAttribution: ahemnell as a volunteer commentedI can't find any references on the web about it being disallowed to start a jQuery selector with ">". I think it's fine.
Just replacing .find with .children won't work because it will not be able to access the tbody > tr and tr at the same time. But there still might be a pretty and more efficient solution using .children.
Comment #23
droplet CreditAttribution: droplet commented@ahemnell,
Leading ">" features provided by selector-native.js but we aim to remove it in these series of issues.
Following code will output errors.
document.querySelectorAll("> div")
Comment #24
ahemnell CreditAttribution: ahemnell as a volunteer commentedHere's my suggestion. One big thing to consider is that I propose to skip test for table > tr, and always just look for table > tbody > tr, because all modern browser wrap orhan tr tags in tbody (*citation needed ). Edit: seems that xhtml doctype omits the tbody wrapping. I guess we have to take table > tr into account, just in case. What do you guys think?
Proposal example:
$(response.selector).children('tbody').children('tr').filter(':visible')
With support for immediate tr something like this is is needed:
$(response.selector).add(response.selector+' tbody').children('tr').filter(':visible')
which is a quite ugly and heavy. Edit2: above is wrong (nested tbodys are added also).
New try:
Comment #26
jhedstromThis should be postponed on #2702233: [backport] Add JavaScript tests for Form API #states: required, visible, invisible, expanded, checked, unchecked so that we know there aren't any regressions once this is in.
Comment #36
xjmPromoting to major alongside the parent.
Comment #40
longwave#2702233: [backport] Add JavaScript tests for Form API #states: required, visible, invisible, expanded, checked, unchecked landed so there seems no reason for this to be postponed.