diff --git a/src/core/js/edit_mode.js b/src/core/js/edit_mode.js index fbf138af5a1d1065473b4159103b3d4bf534f35a..641cd1b6ec2155089ab523ef2802e241985467d5 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);