Problem/Motivation

Convert type selectors to be compatible with with jQuery native-API selector

Proposed resolution

Follow this replacement pattern:

$( ":button" ) -> $( "button, input[type='button']" ).
$( ":checkbox" ) -> $( "[type=checkbox]" )
$( ":file" ) -> $( "[type="file"]" )
$( ":image" ) -> $( "[type="image"]" )
$( ":password" ) -> $( "[type=password]" )
$( ":radio" ) -> $( "[type=radio]" )
$( ":reset" ) -> $( "[type=reset]" )

when using :hidden to select elements, first select the elements using a pure CSS selector, then use .filter(":hidden").
:submit : for better performance in modern browsers, use input[type="submit"], button[type="submit"] instead.
:text : for better performance in modern browsers, use [type="text"] instead.

Remaining Tasks

The most recent patch was created several years before the switch to .es6.js files, so it's likely easier to recreate the changes manually vs applying the patch. An issue fork has been created with a few changes, and contributors should just expand on that as needed using the replacement pattern above.

CommentFileSizeAuthor
#80 2153177-80.patch3.87 KBGauravvvv
#79 2153177-nr-bot.txt150 bytesneeds-review-queue-bot
#55 convert_type_selectors-2153177-55.patch4.68 KBtassilogroeper
#55 interdiff_51-55.txt418 bytestassilogroeper
#54 interdiff-2153177-51-53.txt642 byteser.pushpinderrana
#54 convert_type_selectors-2153177-54.patch4.64 KBer.pushpinderrana
#51 convert_type_selectors-2153177-51.patch4.81 KBtassilogroeper
#49 convert_type_selectors-2153177-49.patch4.81 KBtassilogroeper
#49 interdiff_48-49.txt3.43 KBtassilogroeper
#48 convert_type_selectors-2153177-48.patch4.15 KBtassilogroeper
#46 drupal-js-jquery-type-selectors-2153177-46.patch4.67 KBbabruix
#44 drupal-js-jquery-type-selectors-2153177-44.patch4.67 KBbabruix
#42 drupal-js-jquery-type-selectors-2153177-42.patch3.91 KBbabruix
#40 drupal-js-jquery-type-selectors-2153177-40.patch6.95 KBemma.maria
#38 drupal-js-jquery-type-selectors-2153177-38.patch6.94 KBrteijeiro
#34 drupal-js-jquery-type-selectors-2153177-34.patch6.94 KBestoyausente
#29 drupal-js-jquery-type-selectors-2153177-29.patch6.89 KBbabruix
#26 drupal-js-jquery-type-selectors-2153177-26.patch6.81 KBbabruix
#25 drupal-js-jquery-type-selectors-2153177-24.patch6.81 KBbabruix
#14 drupal-js-jquery-type-selectors-2153177-14.patch7.07 KBnicobot
#13 interdiff.txt3.22 KBnod_
#13 core-js-jquery-type-selectors-2153177-13.patch7.06 KBnod_
#12 interdiff-2153177-10-12.txt7.75 KBtarekdj
#12 type_selectors-2153177-12.patch9.96 KBtarekdj
#10 type_selectors-2153177-10.patch9.67 KBtarekdj
#9 type_selectors-2153177-9.patch9.67 KBtarekdj
#7 type_selectors-2153177-7.patch9.47 KBtarekdj
#1 type_selectors-2153177-1.patch3.5 KBtarekdj

Issue fork drupal-2153177

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

tarekdj’s picture

Status: Active » Needs review
FileSize
3.5 KB
nod_’s picture

Issue summary: View changes
nod_’s picture

Status: Needs review » Needs work

Good start, thanks!

The :input selector needs to be removed as well.

nod_’s picture

Issue tags: +JavaScript clean-up

The last submitted patch, 1: type_selectors-2153177-1.patch, failed testing.

droplet’s picture

- can we don't drop the quotation mark ?

+++ b/core/misc/ajax.js
@@ -200,7 +200,7 @@ Drupal.ajax = function (base, element, element_settings) {
+      if (this.form.find('[type=file]').length) {

find('[type="file"]')

- add back input / button when it's possible ?

input[type="file"]

tarekdj’s picture

Status: Needs work » Needs review
FileSize
9.47 KB

New patch supporting :input

nod_’s picture

for :input it shouldn't be find('*') but find('input,button,textarea,select'), :input should disapear from everywhere.

tarekdj’s picture

tarekdj’s picture

Fixing accidentally removed line

nod_’s picture

Status: Needs review » Needs work

Looking at the sizzle source the replacements should be:

  • for :radio, :checkbox, :file, :password, :image replaced with input[type=XXX]
  • for :submit, :reset replaced with input[type=XXX], button[type=XXX]
  • for :input replaced with .filter('input,select,textarea,button')

Let's be explicit about the replacements and not just select things without tag name.

The content_translation file is borked, needs works.
The formEditor file should just send the string as the filter for the event delegation, no need to select all the elements. Also there is a bug, you're using a variable that you defined in another scope. Run JSHint before you send the patch :)
In tableresponsive, why do you select the parent() element for the headers? That shouldn't be needed.

Getting there :)

tarekdj’s picture

Status: Needs work » Needs review
FileSize
9.96 KB
7.75 KB

I hope this time it will be good :)

nod_’s picture

dropped the changes in form.js, it'll get rewritten in another issue. And the extra semicolon. While it's a valid fix it's out of scope.
The changes in tableresponsive will not work like that. Let's leave it for another issue.

See interdiff. You're removing pieces of a selector that should be needed, it'd be even better if you try to test the changes you make so you can catch syntax error and things that don't work properly.

nicobot’s picture

nicobot’s picture

Status: Needs review » Reviewed & tested by the community
Issue tags: +D8SVQ

Tested changes and following coding standards.

nod_’s picture

Status: Reviewed & tested by the community » Needs review

you can't RTBC a patch you worked on :)

nicobot’s picture

The re-rolled was quite simple and direct, but I'm fine with it :)

nod_’s picture

True, it would have been fine if it was RTBC previously. The ways of the core queue :p

tarekdj’s picture

Assigned: tarekdj » Unassigned
Anonymous’s picture

After applying the patch from #14, a double space was introduced where there should only be one (content_translation.admin.js line 87, between click and table):

$('body').once('translation-entity-admin-bind').on('click', 'table .bundle-settings .translatable input', function (e) {

droplet’s picture

  1. +++ b/core/misc/vertical-tabs.js
    @@ -102,7 +102,7 @@ Drupal.verticalTab = function (settings) {
    +      $('.vertical-tabs-pane').find('input,button,textarea,select').filter(':visible:enabled').first().trigger('focus');
    

    add space after comma: input, button, textarea, select

  2. +++ b/core/modules/content_translation/content_translation.admin.js
    @@ -70,35 +70,35 @@ Drupal.behaviors.contentTranslation = {
    -    .on('click', 'table .field-settings .translatable :input', function (e) {
    +    .on('click', 'input', function (e) {
    

    Please explain why it dropped the selectors.

  3. +++ b/core/modules/edit/js/editors/formEditor.js
    @@ -107,9 +107,9 @@ Drupal.edit.editors.form = Drupal.edit.EditorView.extend({
    -
    +      ¶
    

    space problem

  4. +++ b/core/modules/content_translation/content_translation.admin.js
    @@ -70,35 +70,35 @@ Drupal.behaviors.contentTranslation = {
    +    $('body').once('translation-entity-admin-bind').on('click',  'table .bundle-settings .translatable input', function (e) {
    

    space problem

  5. +++ b/core/modules/views_ui/js/views-admin.js
    @@ -177,7 +177,7 @@ Drupal.behaviors.addItemForm = {
    +  this.$form.find('.views-filterable-options input[type=checkbox]').on('click', $.proxy(this.handleCheck, this));
    

    input[type="checkbox"]. don't drop the quote marks.

droplet’s picture

Status: Needs review » Needs work
nod_’s picture

When re-rolling you should know that the indentation standard changed for JavaScript files.

babruix’s picture

Re-rolled patch from #14.
Applied suggestions 1-5 from #21.

About why it dropped the selectors:

+++ b/core/modules/content_translation/content_translation.admin.js
@@ -70,35 +70,35 @@ Drupal.behaviors.contentTranslation = {
- .on('click', 'table .field-settings .translatable :input', function (e) {
+ .on('click', 'input', function (e) {
Please explain .

Seems it was decided in #13.

babruix’s picture

Status: Needs work » Needs review
FileSize
6.81 KB

#24

babruix’s picture

Added spaces between selectors.

rteijeiro’s picture

Status: Needs review » Reviewed & tested by the community

Patch applies well and nothing seems to be broken. Should I test anything else or is it a RTBC?

droplet’s picture

Status: Reviewed & tested by the community » Needs work
  1. +++ b/core/modules/content_translation/content_translation.admin.js
    @@ -70,35 +70,35 @@
    -      $('body').once('translation-entity-admin-bind').on('click', 'table .bundle-settings .translatable :input', function (e) {
    +      $('body').once('translation-entity-admin-bind').on('click', 'table .bundle-settings .translatable input', function (e) {
    ...
    -          $bundleSettings.find('.operations :input[name$="[language_show]"]').prop('checked', true);
    -          $fieldSettings.find('.translatable :input').prop('checked', true);
    +          $bundleSettings.find('.operations input').filter('input[name$="[language_show]"]').prop('checked', true);
    +          $fieldSettings.find('.translatable input').prop('checked', true);
    ...
    -        .on('click', 'table .field-settings .translatable :input', function (e) {
    +        .on('click', 'input', function (e) {
    

    jQuery :input = input, button, textarea, select

    any reason it dropped the "select" & "textarea" elements?

  2. +++ b/core/modules/edit/js/editors/formEditor.js
    @@ -110,7 +110,7 @@
    +          .on('formUpdated.edit', 'input,button,textarea,select', function (event) {
    
    @@ -147,7 +147,7 @@
    +        .off('change.edit', 'input,button,textarea,select')
    

    add space after comma, please :)

  3. +++ b/core/misc/vertical-tabs.js
    @@ -102,7 +102,7 @@
    +        $('.vertical-tabs-pane').find('input, button, textarea, select').filter(':visible:enabled').first().trigger('focus');
    

    .first() -> eq(0)

babruix’s picture

About 1) I think it was only 'input' there, because there are no other elements.
If you think we still need all these selectors - 'input, button, textarea, select' I have added in this patch.
Also 2) and 3) fixed.

babruix’s picture

Status: Needs work » Needs review

Status: Needs review » Needs work

The last submitted patch, 29: drupal-js-jquery-type-selectors-2153177-29.patch, failed testing.

estoyausente’s picture

Assigned: Unassigned » estoyausente
estoyausente’s picture

estoyausente’s picture

Status: Needs work » Needs review
estoyausente’s picture

Issue tags: +Amsterdam2014
boedah’s picture

Title: Convert type selectors to be compatible with with jQuery native-API selector » Convert type selectors to be compatible with jQuery native-API selector
rteijeiro’s picture

Assigned: estoyausente » Unassigned
FileSize
6.94 KB

Re-rolled!

emma.maria’s picture

Issue tags: +Needs reroll
emma.maria’s picture

Rerolled patch

nod_’s picture

Status: Needs review » Needs work
  1. +++ b/core/misc/vertical-tabs.js
    @@ -102,7 +102,7 @@
    +        $('.vertical-tabs-pane').find('input, button, textarea, select').filter(':visible:enabled').eq(0).trigger('focus');
    

    Are you sure about that CSS class change? wouldn't want to break stuff :)

  2. +++ b/core/modules/content_translation/content_translation.admin.js
    @@ -70,35 +70,35 @@
    +      $(context).find('table .bundle-settings .translatable').find('input, button, textarea, select').once('translation-entity-admin-hide', function () {
    

    Shouldn't be possible to use .once like that. Needs to be replaced with .once('translation-entity-admin-hide').each(function () {…

  3. +++ b/core/modules/content_translation/content_translation.admin.js
    @@ -70,35 +70,35 @@
    +      $('body').once('translation-entity-admin-bind').on('click', 'table .bundle-settings .translatable input, button, textarea, select', function (e) {
    

    Let's not change that one, the selector is not working like you'd expect. Like that it listen to click on all buttons, textarea and select of the page.

  4. +++ b/core/modules/content_translation/content_translation.admin.js
    @@ -70,35 +70,35 @@
    +          $bundleSettings.find('.operations input').filter('input[name$="[language_show]"], button, textarea, select').prop('checked', true);
    

    Similar thing going on here, let's not change it yet.

  5. +++ b/core/modules/content_translation/content_translation.admin.js
    @@ -70,35 +70,35 @@
    +        .on('click', 'input, button, textarea, select', function (e) {
    

    Same here.

  6. +++ b/core/modules/quickedit/js/editors/formEditor.js
    @@ -111,7 +111,7 @@
    +          .on('formUpdated.quickedit', 'input,button,textarea,select', function (event) {
    

    Just needs some spaces after , but fine otherwise.

  7. +++ b/core/modules/quickedit/js/views/EditorView.js
    @@ -184,7 +184,7 @@
    +        $form.find('input[type!="hidden"][type!="submit"],textarea')
    

    This one looks wrong, let's not change it.

babruix’s picture

Status: Needs work » Needs review
FileSize
3.91 KB

Convert type selectors, changes from comment #41

Status: Needs review » Needs work

The last submitted patch, 42: drupal-js-jquery-type-selectors-2153177-42.patch, failed testing.

babruix’s picture

Status: Needs work » Needs review
FileSize
4.67 KB

Applied changes from comment #41.

tarekdj’s picture

Status: Needs review » Needs work
+++ b/core/modules/views_ui/js/views-admin.js
@@ -864,7 +864,7 @@
+    this.$input = this.$parent.find('input[type=checkbox], input[type=radio]');

Minor change:
this.$input = this.$parent.find('input[type="checkbox"], input[type="radio"]');

babruix’s picture

Status: Needs work » Needs review
FileSize
4.67 KB

Added minor change from comment #45.

tassilogroeper’s picture

Issue tags: +Barcelona2015, +Needs reroll

the patch produces merge conflict in ajax.js - due to outdated patch.
FYI working on it at BarcelonaCon 2015 extended sprint.

tassilogroeper’s picture

the straight re-rolled patch.
merge conflict in ajax.js has been removed during development of the master, no need for to fix something in there.

tassilogroeper’s picture

cleaned the code up. now it is a bit more readable.

hass’s picture

Status: Needs review » Needs work
+++ b/core/modules/views_ui/js/views-admin.js
@@ -268,11 +268,13 @@
+    ¶

there is a tab in the patch

tassilogroeper’s picture

@hass: thanks, I have missed that.
no interdiff, coz empty space replaced by empty space...

tassilogroeper’s picture

Status: Needs work » Needs review
hass’s picture

Status: Needs review » Needs work
+++ b/core/misc/vertical-tabs.js
@@ -124,7 +124,12 @@
+        $('.vertical-tabs__pane')
+          .find('input, button, textarea, select')
+          .filter(':visible:enabled')
+          .eq(0)
+          .trigger('focus');
+        $('.vertical-tabs__pane').find('input, button, textarea, select').filter(':visible:enabled').eq(0).trigger('focus');

This looks like the same twice.

er.pushpinderrana’s picture

Status: Needs work » Needs review
FileSize
4.64 KB
642 bytes

Removed the redundant line as per #53.

tassilogroeper’s picture

@er.pushpinderrana sorry, had this duplicated line inside. But we need to remove the later, not the more explicit and readable one, please. Patch atteched

Status: Needs review » Needs work

The last submitted patch, 55: convert_type_selectors-2153177-55.patch, failed testing.

Status: Needs work » Needs review

Version: 8.0.x-dev » 8.1.x-dev

Drupal 8.0.6 was released on April 6 and is the final bugfix release for the Drupal 8.0.x series. Drupal 8.0.x will not receive any further development aside from security fixes. Drupal 8.1.0-rc1 is now available and sites should prepare to update to 8.1.0.

Bug reports should be targeted against the 8.1.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.2.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

droplet’s picture

Version: 8.1.x-dev » 8.2.x-dev
Status: Needs review » Postponed

Thanks ALL for your hard-working! Let's do it when we have more JS test cases covered.

Version: 8.2.x-dev » 8.3.x-dev

Drupal 8.2.0-beta1 was released on August 3, 2016, which means new developments and disruptive changes should now be targeted against the 8.3.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.3.x-dev » 8.4.x-dev

Drupal 8.3.0-alpha1 will be released the week of January 30, 2017, which means new developments and disruptive changes should now be targeted against the 8.4.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.4.x-dev » 8.5.x-dev

Drupal 8.4.0-alpha1 will be released the week of July 31, 2017, which means new developments and disruptive changes should now be targeted against the 8.5.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.5.x-dev » 8.6.x-dev

Drupal 8.5.0-alpha1 will be released the week of January 17, 2018, which means new developments and disruptive changes should now be targeted against the 8.6.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.6.x-dev » 8.7.x-dev

Drupal 8.6.0-alpha1 will be released the week of July 16, 2018, which means new developments and disruptive changes should now be targeted against the 8.7.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.7.x-dev » 8.8.x-dev

Drupal 8.7.0-alpha1 will be released the week of March 11, 2019, which means new developments and disruptive changes should now be targeted against the 8.8.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.8.x-dev » 8.9.x-dev

Drupal 8.8.0-alpha1 will be released the week of October 14th, 2019, which means new developments and disruptive changes should now be targeted against the 8.9.x-dev branch. (Any changes to 8.9.x will also be committed to 9.0.x in preparation for Drupal 9’s release, but some changes like significant feature additions will be deferred to 9.1.x.). For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

Version: 8.9.x-dev » 9.1.x-dev

Drupal 8.9.0-beta1 was released on March 20, 2020. 8.9.x is the final, long-term support (LTS) minor release of Drupal 8, which means new developments and disruptive changes should now be targeted against the 9.1.x-dev branch. For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

Version: 9.1.x-dev » 9.2.x-dev

Drupal 9.1.0-alpha1 will be released the week of October 19, 2020, which means new developments and disruptive changes should now be targeted for the 9.2.x-dev branch. For more information see the Drupal 9 minor version schedule and the Allowed changes during the Drupal 9 release cycle.

Version: 9.2.x-dev » 9.3.x-dev

Drupal 9.2.0-alpha1 will be released the week of May 3, 2021, which means new developments and disruptive changes should now be targeted for the 9.3.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

bnjmnm made their first commit to this issue’s fork.

bnjmnm’s picture

Status: Postponed » Needs review

Version: 9.3.x-dev » 9.4.x-dev

Drupal 9.3.0-rc1 was released on November 26, 2021, which means new developments and disruptive changes should now be targeted for the 9.4.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

xjm’s picture

Priority: Normal » Major
Issue tags: +Drupal 10

Promoting to major alongside the parent.

mradcliffe’s picture

bnjmnm’s picture

Issue summary: View changes

Version: 9.4.x-dev » 9.5.x-dev

Drupal 9.4.0-alpha1 was released on May 6, 2022, which means new developments and disruptive changes should now be targeted for the 9.5.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.5.x-dev » 10.1.x-dev

Drupal 9.5.0-beta2 and Drupal 10.0.0-beta2 were released on September 29, 2022, which means new developments and disruptive changes should now be targeted for the 10.1.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

needs-review-queue-bot’s picture

Status: Needs review » Needs work
FileSize
150 bytes

The Needs Review Queue Bot tested this issue. It either no longer applies to Drupal core, or fails the Drupal core commit checks. Therefore, this issue status is now "Needs work".

Apart from a re-roll or rebase, this issue may need more work to address feedback in the issue or MR comments. To progress an issue, incorporate this feedback as part of the process of updating the issue. This helps other contributors to know what is outstanding.

Consult the Drupal Contributor Guide to find step-by-step guides for working with issues.

Gauravvvv’s picture

Status: Needs work » Needs review
FileSize
3.87 KB

I have re-rolled the patch for 10.1.x please review

Version: 10.1.x-dev » 11.x-dev

Drupal core is moving towards using a “main” branch. As an interim step, a new 11.x branch has been opened, as Drupal.org infrastructure cannot currently fully support a branch named main. New developments and disruptive changes should now be targeted for the 11.x branch, which currently accepts only minor-version allowed changes. For more information, see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

smustgrave’s picture

Priority: Major » Normal
Status: Needs review » Reviewed & tested by the community
Issue tags: -js-novice, -JavaScript clean-up, -D8SVQ, -Amsterdam2014, -Barcelona2015, -Drupal 10, -Portland2022 +Needs Review Queue Initiative

Cleaning up the tags.

Searched fore each of the patterns manually in core and appears reroll got them.

Downgrading to normal though as if this was major like to think it would of been addressed.

Status: Reviewed & tested by the community » Needs work

The last submitted patch, 80: 2153177-80.patch, failed testing. View results