From 7c74c3d29f524e7e8b576c8cf765504b58a3ca29 Mon Sep 17 00:00:00 2001 From: mivasiliauskas <36185103+mivasiliauskas@users.noreply.github.com> Date: Sat, 15 Feb 2020 11:20:53 +0200 Subject: [PATCH] Fixed note-editor bug (#404) * Fixed note-editor bug that would raise error on edit when no notes are present * Added additional check so that no errors would be thrown when no notes are present --- modules/ui/notes-editor.js | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/modules/ui/notes-editor.js b/modules/ui/notes-editor.js index 011a325c..07376acc 100644 --- a/modules/ui/notes-editor.js +++ b/modules/ui/notes-editor.js @@ -6,7 +6,7 @@ function editNotes(id, name) { for (const note of notes) {select.options.add(new Option(note.id, note.id));} // select an object - if (notes.length) { + if (notes.length || id) { if (!id) id = notes[0].id; let note = notes.find(note => note.id === id); if (note === undefined) { @@ -19,10 +19,9 @@ function editNotes(id, name) { notesName.value = note.name; notesText.value = note.legend; } else { - if (!notes.length) { - const value = "There are no added notes. Click on element (e.g. label) and add a free text note"; - document.getElementById("notesText").value = value; - } + const value = "There are no added notes. Click on element (e.g. label) and add a free text note"; + document.getElementById("notesText").value = value; + document.getElementById("notesName").value = ""; } // open a dialog @@ -54,12 +53,14 @@ function editNotes(id, name) { function changeName() { const id = document.getElementById("notesSelect").value; const note = notes.find(note => note.id === id); + if (!note) return; note.name = this.value; } function changeText() { const id = document.getElementById("notesSelect").value; const note = notes.find(note => note.id === id); + if (!note) return; note.legend = this.value; }