From 1f9dd35e8965c30543ace33812d590c25cc7967b Mon Sep 17 00:00:00 2001 From: Ethan Dalool Date: Thu, 13 Jul 2017 23:07:44 -0700 Subject: [PATCH] Add data-editor-empty-text attribute. When the display element specifies this attribute, it will be used when the user leaves that field empty. --- frontends/etiquette_flask/static/common.js | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/frontends/etiquette_flask/static/common.js b/frontends/etiquette_flask/static/common.js index ac1e1c9..d5327e7 100644 --- a/frontends/etiquette_flask/static/common.js +++ b/frontends/etiquette_flask/static/common.js @@ -49,7 +49,15 @@ function Editor(elements, on_open, on_save, on_cancel) display_element.classList.add("hidden"); edit_element.classList.remove("hidden"); - edit_element.value = display_element.innerText; + var empty_text = display_element.dataset.editorEmptyText; + if (empty_text !== undefined && display_element.innerText == empty_text) + { + edit_element.value = ""; + } + else + { + edit_element.value = display_element.innerText; + } } this.open_button.classList.add("hidden") this.save_button.classList.remove("hidden"); @@ -63,7 +71,14 @@ function Editor(elements, on_open, on_save, on_cancel) var display_element = this.display_elements[index]; var edit_element = this.edit_elements[index]; - display_element.innerText = edit_element.value; + if (display_element.dataset.editorEmptyText !== undefined && edit_element.value == "") + { + display_element.innerText = display_element.dataset.editorEmptyText; + } + else + { + display_element.innerText = edit_element.value; + } } this.close();