From 08d2d6ae5195eaf86df7bb3fa81d26b5cc861b0d Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Henrik=20tom=20W=C3=B6rden?= <h.tomwoerden@indiscale.com>
Date: Tue, 10 Oct 2023 22:26:11 +0200
Subject: [PATCH] FIX: fix scoping to allow lists

---
 src/core/js/edit_mode.js | 36 +++++++++++++++++++++++++-----------
 1 file changed, 25 insertions(+), 11 deletions(-)

diff --git a/src/core/js/edit_mode.js b/src/core/js/edit_mode.js
index fbf138af..641cd1b6 100644
--- a/src/core/js/edit_mode.js
+++ b/src/core/js/edit_mode.js
@@ -1031,26 +1031,40 @@ var edit_mode = new function () {
                         // The button to show the input field for manual ID insertion
                         var manualInsertButton = $('<button title="Insert Entity Id manually." class="btn btn-link caosdb-update-entity-button caosdb-f-list-item-button"><i class="bi-pencil"></i></button>');
                         $(manualInsertButton).click(function () {
-                            // show ID input; hide dropdown
-                            $(result).find('.dropdown').hide();
-                            $(result).find('input').show();
+                            // toggle input
+                            // forward:
+                            if ($(result).find('input.caosdb-f-manual-id-insert').is(':hidden')){
+                                // show ID input; hide dropdown
+                                $(result).find('.dropdown').hide();
+                                $(result).find('input.caosdb-f-manual-id-insert').show();
+                                $('.caosdb-f-entity-save-button').hide()
+                            } else {
+                                // backward:
+                                $(result).find('input.caosdb-f-manual-id-insert')[0].dispatchEvent(new KeyboardEvent('keyup', {'key':'Enter'}));
+                            }
                         });
                         // Add input for manual ID insertion
-                        idinput = $("<input type='number' value=''></input>")
+                        idinput = $("<input type='number' class='caosdb-f-manual-id-insert' value=''></input>")
                         idinput.hide()
                         // Add callback for pressing Enter: the insertion is completed
                         idinput.on('keyup', function (e) {
                             if (e.key === 'Enter' || e.keyCode === 13) {
                                 // hide the input, show the dropdown again and append the value that
                                 // was entered to the candidates and select that item
-                                idinput.hide();
-                                var sel_id = idinput[0].value
-                                select.append(`<option value="${sel_id}">ID: ${sel_id}</option>`);
-                                // workaround for selectpicker bug (options are
-                                // doubled otherwise)
-                                select.selectpicker('destroy');
-                                select.selectpicker('val', `${sel_id}`);
+                                $(result).find('input.caosdb-f-manual-id-insert').hide();
+                                var sel_id = $(result).find('input.caosdb-f-manual-id-insert')[0].value
+                                if (sel_id!=""){
+                                    if ($(result).find(`option[value="${sel_id}"]`).length==0){
+                                        select.append(`<option value="${sel_id}">ID: ${sel_id}</option>`);
+                                        // workaround for selectpicker bug (options are
+                                        // doubled otherwise)
+                                        select.selectpicker('destroy');
+                                        select.selectpicker();
+                                    }
+                                    select.selectpicker('val', `${sel_id}`);
+                                }
                                 $(result).find('.dropdown').show();
+                                $('.caosdb-f-entity-save-button').show()
                             }
                         });
                         result.append(idinput);
-- 
GitLab