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
- #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.
Comment | File | Size | Author |
---|---|---|---|
#13 | core-weight-number-field-1518182-13.patch | 1.73 KB | japerry |
#3 | core-weight-number-field-1518182-3.patch | 1.15 KB | nod_ |
Comments
Comment #1
sunRevised the summary.
Comment #2
xjmYou 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).
Comment #3
nod_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.
Comment #4
nod_Comment #5.0
(not verified) CreditAttribution: commentedUpdated issue summary.
Comment #5.1
nod_D8 number solution
Comment #5.2
nod_wrong information
Comment #6
tim.plunkettThis issue needs some consensus before an approach is coded.
Comment #6.0
tim.plunkettUpdated issue summary.
Comment #8
japerryWe'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:
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.
Comment #9
japerryHere is a patch for 8.3 and applies cleanly against 8.2 and 8.1 HEAD.
Marking needs work as it probably needs tests.
Comment #10
japerryComment #11
japerryComment #13
japerryUpdate for 8.4 head/8.3.0