Problem

  • #type 'weight' elements render in an unpredictable way.
  • It's not apparent at which point a text field is output instead.
  • One cannot override this limit/decision for a particular element.

Goal

  • Make #type 'weight' consistently output a weight selector.
  • Use an element #property to control the maximum options for displaying a select input (vs. text field).
  • Make weight fields in tabledrag forms use a text field, since they are repeated often and invisible either way.

Details

  • #1346760: Add a scalable weight select element made #type 'weight' elements conditionally render into text input elements to resolve performance issues for large numbers of items.
  • The weight element now renders as a text field instead of a select when the maximum allowed value is more than the configuration variable 'drupal_weight_select_max' (defaults to DRUPAL_WEIGHT_SELECT_MAX [currently 100]).

Proposed resolution

  • Use the new number input type for D8.
  • Add an additional property for the element (something like #max_select_items that determines the maximum weight for a select element to be used.
  • Set this property to 0 for weight fields in tabledrag enhanced tables.

Remaining tasks

Build consensus.

API changes

API addition: An additional property may be added for the weight element type.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

sun’s picture

Revised the summary.

xjm’s picture

You and your cowboy summary headers. :) Also, I disagree with the goal -- a select element should not be used when there are hundreds or thousands of items (regardless of context).

nod_’s picture

The D8 solution got lost in the previous thread. Replace the textfield by a number input type, just landed in core.

Try it in Opera or chrome, it's pretty cool.

nod_’s picture

Status: Active » Needs review

Status: Needs review » Needs work

The last submitted patch, core-weight-number-field-1518182-3.patch, failed testing.

Anonymous’s picture

Issue summary: View changes

Updated issue summary.

nod_’s picture

Issue summary: View changes

D8 number solution

nod_’s picture

Issue summary: View changes

wrong information

tim.plunkett’s picture

Status: Needs work » Active

This issue needs some consensus before an approach is coded.

tim.plunkett’s picture

Issue summary: View changes

Updated issue summary.

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.

japerry’s picture

Version: 8.1.x-dev » 8.3.x-dev
Category: Task » Feature request

We're running into this issue with panels. While we could create some hacky code (and probably will) to get a number field, it'd be great if we moved to using a number widget in general.

This has partially been committed, looking at the code below:

    // If the number of options is small enough, use a select field.
    $max_elements = \Drupal::config('system.site')->get('weight_select_max');
    if ($element['#delta'] <= $max_elements) {
      $element['#type'] = 'select';
      $weights = array();
      for ($n = (-1 * $element['#delta']); $n <= $element['#delta']; $n++) {
        $weights[$n] = $n;
      }
      $element['#options'] = $weights;
      $element += $element_info_manager->getInfo('select');
    }
    // Otherwise, use a text field.
    else {
      $element['#type'] = 'number';
      // Use a field big enough to fit most weights.
      $element['#size'] = 10;
      $element += $element_info_manager->getInfo('number');
    }

Especially now that the number field is widely accepted by browsers, the existing accessibility issues I think have been addressed. Basically the patch in #3 just needs to be re-rolled for 8.2/8.3.

japerry’s picture

Status: Active » Needs work

Here is a patch for 8.3 and applies cleanly against 8.2 and 8.1 HEAD.

Marking needs work as it probably needs tests.

japerry’s picture

japerry’s picture

Status: Needs work » Needs review

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.

japerry’s picture

Status: Needs review » Needs work

The last submitted patch, 13: core-weight-number-field-1518182-13.patch, failed testing.

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.

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.

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.

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.