Table drag row region doesn't update when Choices.js is applied to select inputs

Created on 26 April 2023, over 1 year ago
Updated 21 July 2023, over 1 year ago

Problem/Motivation

Table drag functionality isn't updating a content type field region on Choices.js select elements.

Steps to reproduce

Choices configuration:

  1. Enable Choices Globally
  2. Apply Choices.js to all select elements - select
  3. Include Choices.js on every page

Go to edit the article content type manage form display. Drag a field from the content region to the disabled region, the field will not stay in the disabled region and will return to the content region.

The region can be adjusted by showing the row weights and changing the value on the select elements.

Proposed resolution

Prevent choices from applying to any of the select inputs that are part of a table drag interface.

The core tabledrag.js file adds a class of draggable to the table row. This parent class can be targeted to prevent choices.js from taking over any select inputs in the table row.

🐛 Bug report
Status

Fixed

Version

2.0

Component

Code

Created by

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

  • Issue created by @JamesPosko
  • I need a bit of help with the issue fork and creating the merge request. I'm following the documentation on the Drupal site but I ended up pushing the changes to the 2.x branch and not the 3356663-table-drag-row branch in the issue fork. How should I proceed with the merge request? Thank you for your help as I learn and work through the process for Drupal projects.

  • 🇩🇪Germany Anybody Porta Westfalica

    @JamesPosko that's no problem, we can also create a MR from 2.x.

    For the future, simply click "Show commands" here above, there's a guide with the steps required. I think you missed one, for example the last. Nothing untypical ;)

  • Open in Jenkins → Open on Drupal.org →
    Core: 10.0.7 + Environment: PHP 8.1 & MySQL 8
    last update over 1 year ago
    24 pass
  • @anybody opened merge request.
  • Status changed to Needs review over 1 year ago
  • @Anybody I'm glad to hear this can still work as is with the 2.x branch. Thank you for making the MR from the 2.x branch in this issue fork and for your support.

    The MR contains the proposed change to target the parent node with the class .draggable and not apply choices.js to the child select elements. The code comment has been updated as well.

  • 🇩🇪Germany Anybody Porta Westfalica

    @JamesPosko instead of replacing existing selectors, shouldn't we better simply add .draggable as exclude or can we be 100% sure that the previously existing selectors are no more needed?

  • I think the exclusion of .draggable should replace the need to search for the other two selectors that are currently being excluded. None of the select elements in the table drag row have the Choices.js applied. The single exclusion of .draggable seems to work when rearranging table drag elements on paragraphs, menus, blocks, roles, and views. It is a good question if another core JS feature might use weight or parent?

  • I came across another instance where the current ends with selector isn't matching a select. A new attribute selector that contains "weights" would need to be excluded. In the Search API manage processors admin config for processor order uses table drag with weight selects but the attribute uses "weights" instead of "weight" (data-drupal-selector="edit-processors-number-field-boost-weights-preprocess-index").

  • 🇩🇪Germany Anybody Porta Westfalica

    Thanks @JamesPosko - we won't (be able) to solve this for contrib cases. For that a custom exclusion selector is needed. From my perspective it's a bug / non-Drupal-best-practice value used in Search API. You may open an issue there.

  • Agreed. There doesn't seem to be a standard way the attribute is being implemented. Though, all these selects are part of the table drag implementation and the new exclude of .draggable should exclude all these selectors.

    Weight, parent and region selects are mostly used with the table drag interface. I think the previously existing selectors can be replaced by .draggable.

  • 🇩🇪Germany Anybody Porta Westfalica

    Okay so I guess there are two tasks left as result:
    1. Ensure the MR works for all core draggable cases (best would be to have automated tests, but that might also be disproportionate)
    2. Create and implement a follow-up issues to add a custom exclude setting, where selectors like in #8 can be added

    @JamesPosko would you do this?

  • Since changing to the draggable exclusion, table drag is working on core menus, manage form display, manage display, views, roles, and blocks. The update is working on contrib paragraphs and the Search API as well.

    I haven't created an automated test but will learn and try.

    I can create the follow-up issue feature request to add a custom exclude setting.

  • 🇩🇪Germany Anybody Porta Westfalica

    Thank you very much @JamesPosko! That's great and highly appreciated :)

  • Open in Jenkins → Open on Drupal.org →
    Core: 10.0.7 + Environment: PHP 8.1 & MySQL 8
    last update over 1 year ago
    19 pass, 2 fail
  • I added a test to the global functional tests to check that choices isn't applied to the manage form display table drag selects. I'm not sure why the test for the choices widget failed, all tests are passing on my local development environment with the same versions.

  • Status changed to Needs work over 1 year ago
  • 🇩🇪Germany Anybody Porta Westfalica

    Thanks @JamesPosko, so this needs work to fix the tests. Best would be to have tests for all the expected Drupal Core exclusions.

  • Open in Jenkins → Open on Drupal.org →
    Core: 10.0.7 + Environment: PHP 8.1 & MySQL 8
    last update over 1 year ago
    25 pass
  • Ran the tests again and they all passed this time. I'm not sure what happened on the first run but after going through some of the documentation I thought the first step would be to run the test again.

    Does the new test added meet the expectations on the core table drag functionality?

    What are the other Drupal core exclusions needed?

  • Open on Drupal.org →
    Core: 10.0.7 + Environment: PHP 8.1 & MySQL 8
    1:14
    1:14
    Queueing
  • @anybody opened merge request.
  • 🇩🇪Germany Anybody Porta Westfalica

    Thanks @JamesPosko great!

    I think we should add tests for all core pages (matching the different scenarios), where dragging is used.
    Some use nested/tree dragging, some not.

    I remember the following ones for now:

    • Node Fields (solved)
    • Menu Items
    • Blocks
    • Taxonomy Terms
    • Roles
    • Maybe some core settings pages

    I don't thing we have to test all, but we should test the different variants (tree / flat) and the most important, less ege-cases, do you agree?

    Once done. could we have a test-only patch here to ensure the test works and broke before? So we can be 100% sure!

  • I'll take a look at a few of the different core admin pages and add test for the different variants (tree / flat).

    Would a test-only patch mean to create a patch that contained the tests that can be applied to the feature branch / merge request?

  • 🇩🇪Germany Anybody Porta Westfalica

    Thanks @JamesPosko. Exactly, a test-only patch means, only the patch, not the fixes. So it's expected to fail when tested here.

    Typically just uploaded as patch file, not as MR. But a separate MR should also work, alternatively.

  • So remove the tests from MR23 but keep the change to use .draggable, correct?

    Create a new branch in this issue fork to apply the tests in a different MR?

  • 🇩🇪Germany Anybody Porta Westfalica

    No. Keep the current MR as-is (plus additonal tests).

    Additionally upload a patch file (or create a MR) that ONLY contains the tests. So they are expected to fail under old conditions, without the changes.

    So it's kind of a vice-versa test "would this have failed, before we fixed it, as we would expect". :)

  • Open in Jenkins → Open on Drupal.org →
    Core: 10.0.7 + Environment: PHP 8.1 & MySQL 8
    last update over 1 year ago
    27 pass
  • Status changed to Needs review over 1 year ago
  • Added a test to run on menu Administration edit page and one to run on views Content filter rearrange UI dialog along with the first test on the manage form display.

    There is a new branch that has the new test but not the update to the global JavaScript and the tests fail.

  • Assigned to Grevil
  • 🇩🇪Germany Anybody Porta Westfalica

    Thanks! We'll take a look! Super awesome :)

    @Grevil: Perhaps create a test-only patch file or MR that should fail? If it doesn't take too much time...

  • Open in Jenkins → Open on Drupal.org →
    Core: 10.0.7 + Environment: PHP 8.1 & MySQL 8
    last update over 1 year ago
    11 pass, 2 fail
  • @jamesposko opened merge request.
  • I think the MR 25 based on branch 3356663-tests-no-table-drag-row-change in this same issue fork is showing the 3 new test failing. The branch only contains the tests and not the global JavaScript update. Is this how a test-only set should be created?

  • Status changed to RTBC over 1 year ago
  • 🇩🇪Germany Grevil

    There were 3 errors: [...]

    Nice! Tests LGTM! RTBC +1

  • Status changed to Fixed over 1 year ago
  • 🇩🇪Germany Grevil

    Created a new release!

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

Production build 0.71.5 2024