If a draggable list (like menu tree) has more than 100 items the weight field is converted from select to textfield. That's quite fine but if the users reorder the items by dragging (like most will do) the weights in the textfield are reset starting from the value of the first item in the list, incrementing it till the last item (not from the lowest value).
If I have 151 items in the list the weight will start from -50 and end on 100. That's also fine but If I drag the 151th item to the top, the weights will be reset and will start from 100 (the weight if the 151th item). Like this it will increment until max int(11) is reached which is the limit for the db column.
If the items are < 100 a select is used, which on the other hand loops over one select and gets all the possible weight values and resets all of them starting with the lowest possible and when the max is reached it repeats this max. Here is the code in tabledrag.js:
if ($(targetElement).is('select')) {
// Get a list of acceptable values.
var values = [];
$('option', targetElement).each(function () {
values.push(this.value);
});
var maxVal = values[values.length - 1];
// Populate the values in the siblings.
$(targetClass, siblings).each(function () {
// If there are more items than possible values, assign the maximum value to the row.
if (values.length > 0) {
this.value = values.shift();
}
else {
this.value = maxVal;
}
});
}
else {
// Assume a numeric input field.
var weight = parseInt($(targetClass, siblings[0]).val(), 10) || 0;
$(targetClass, siblings).each(function () {
this.value = weight;
weight++;
});
}
I think in case we have > 100 items the logic that the weights are reset starting from the lowest weight value should be preserved.
| Comment | File | Size | Author |
|---|
Comments
Comment #1
angel.hHere is the patch.
Comment #2
angel.hShoot, I misspelled "infinite" in the patch name. :)
Comment #3
mgiffordIs this also a bug in Drupal 8?
Comment #4
pieterdcUnassigning angel.h because he's not working on this at the moment.
Linking #1007746: Reordering fails with more than 100 items in a menu because it looks like that patch got more traction so far.