[Patchew-devel] [PATCH 10/17] mods: do not allow creating duplicate map items

Paolo Bonzini pbonzini at redhat.com
Thu May 2 11:17:57 UTC 2019


The code for that was there but more or less stubbed out, fix it.
---
 static/js/config-editor.js | 11 ++++++-----
 1 file changed, 6 insertions(+), 5 deletions(-)

diff --git a/static/js/config-editor.js b/static/js/config-editor.js
index f15211f..c0f326f 100644
--- a/static/js/config-editor.js
+++ b/static/js/config-editor.js
@@ -70,9 +70,10 @@ function properties_save(btn) {
         });
 }
 
-function collect_items(btn) {
-    $(btn).parent().parent().find(".map-item");
-    return {};
+function collect_items(container) {
+    return container.find("> .items > .item > .item-heading > .item-name").map(function() {
+        return $(this).text();
+    }).get();
 }
 
 function map_add_item(btn) {
@@ -81,8 +82,8 @@ function map_add_item(btn) {
         return;
     }
     container = $(btn).parent().parent();
-    if (name in collect_items(btn)) {
-        alert(test_name + " already exists.");
+    if (collect_items(container).includes(name)) {
+        alert(name + " already exists.");
         return;
     }
     if (name.indexOf(".") >= 0) {
-- 
2.21.0





More information about the Patchew-devel mailing list