luci-base: ui.js: do not forcibly sort synamic list items
authorJo-Philipp Wich <jo@mein.io>
Wed, 14 Aug 2019 20:44:54 +0000 (22:44 +0200)
committerJo-Philipp Wich <jo@mein.io>
Wed, 14 Aug 2019 20:46:19 +0000 (22:46 +0200)
Ref: https://forum.openwrt.org/t/cannot-save-certain-fields/42738/2
Signed-off-by: Jo-Philipp Wich <jo@mein.io>
modules/luci-base/htdocs/luci-static/resources/ui.js

index 29233dec02472f3ff5a3c7de28c5bf0b8c5bc182..11886b91fe1ba31dcc4f2fe02fb974279c0f680b 100644 (file)
@@ -1199,7 +1199,7 @@ var UIDynamicList = UIElement.extend({
                                        'name': this.options.name,
                                        'value': value })]);
 
-               dl.querySelectorAll('.item, .add-item').forEach(function(item) {
+               dl.querySelectorAll('.item').forEach(function(item) {
                        if (exists)
                                return;
 
@@ -1210,10 +1210,13 @@ var UIDynamicList = UIElement.extend({
 
                        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);
+               }
+
                dl.dispatchEvent(new CustomEvent('cbi-dynlist-change', {
                        bubbles: true,
                        detail: {