From b208af478d4856a7d51df5ba710e9ad0e27bf5fb Mon Sep 17 00:00:00 2001 From: Russ Long Date: Fri, 1 May 2026 13:58:48 -0400 Subject: [PATCH] fix: use explicit numeric comparison in tomselect for reliable sorting --- resources/views/components/tomselect.blade.php | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/resources/views/components/tomselect.blade.php b/resources/views/components/tomselect.blade.php index ab114cf..64c1fbf 100644 --- a/resources/views/components/tomselect.blade.php +++ b/resources/views/components/tomselect.blade.php @@ -18,18 +18,16 @@ copyClassesToDropdown: false, dropdownParent: 'body', controlInput: '', - 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: { field: 'text', direction: 'asc', 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; } } });