fix: use explicit numeric comparison in tomselect for reliable sorting

This commit is contained in:
2026-05-01 13:58:48 -04:00
parent 7d9af30ed3
commit b208af478d
@@ -18,18 +18,16 @@
copyClassesToDropdown: false, copyClassesToDropdown: false,
dropdownParent: 'body', dropdownParent: 'body',
controlInput: '<input>', controlInput: '<input>',
sortField: [{
field: 'text',
direction: 'asc'
}],
// Natural sort plugin or custom sorter:
// We use a custom sort function to handle the "1 - ..." format
// This ensures "1" < "2" < "10"
sortField: { sortField: {
field: 'text', field: 'text',
direction: 'asc', direction: 'asc',
func: function(a, b) { func: function(a, b) {
return a.text.localeCompare(b.text, undefined, {numeric: true, sensitivity: 'base'}); const valA = parseInt(a.text, 10);
const valB = parseInt(b.text, 10);
if (isNaN(valA) || isNaN(valB)) {
return a.text.localeCompare(b.text);
}
return valA - valB;
} }
} }
}); });