luci-base: cbi.js: do not forcibly sort synamic list items
authorJo-Philipp Wich <jo@mein.io>
Wed, 14 Aug 2019 20:34:02 +0000 (22:34 +0200)
committerJo-Philipp Wich <jo@mein.io>
Wed, 14 Aug 2019 20:48:12 +0000 (22:48 +0200)
Ref: https://forum.openwrt.org/t/cannot-save-certain-fields/42738/2
Signed-off-by: Jo-Philipp Wich <jo@mein.io>
(backported from commit dbf83e35bb6e4d203eca917d4dfef2b270dd34ff)

modules/luci-base/htdocs/luci-static/resources/cbi.js

index e203c63fffbac113e64aa646585880a680c549f3..fa61cf6447ebc4e0cb1c68f132a04fc943620e0a 100644 (file)
@@ -903,7 +903,7 @@ CBIDynamicList = {
                                        'name': dl.getAttribute('data-prefix'),
                                        'value': value })]);
 
-               dl.querySelectorAll('.item, .add-item').forEach(function(item) {
+               dl.querySelectorAll('.item').forEach(function(item) {
                        if (exists)
                                return;
 
@@ -911,10 +911,13 @@ CBIDynamicList = {
 
                        if (hidden && hidden.value === value)
                                exists = true;
-                       else if (!hidden || hidden.value >= value)
-                               exists = !!item.parentNode.insertBefore(new_item, item);
                });
 
+               if (!exists) {
+                       var ai = dl.querySelector('.add-item');
+                       ai.parentNode.insertBefore(new_item, ai);
+               }
+
                cbi_d_update();
        },