Add data-editor-empty-text attribute.

When the display element specifies this attribute, it will be used when
the user leaves that field empty.
This commit is contained in:
voussoir 2017-07-13 23:07:44 -07:00
parent 22c0163f5b
commit 1f9dd35e89

View file

@ -49,8 +49,16 @@ function Editor(elements, on_open, on_save, on_cancel)
display_element.classList.add("hidden"); display_element.classList.add("hidden");
edit_element.classList.remove("hidden"); edit_element.classList.remove("hidden");
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; edit_element.value = display_element.innerText;
} }
}
this.open_button.classList.add("hidden") this.open_button.classList.add("hidden")
this.save_button.classList.remove("hidden"); this.save_button.classList.remove("hidden");
this.cancel_button.classList.remove("hidden"); this.cancel_button.classList.remove("hidden");
@ -63,8 +71,15 @@ function Editor(elements, on_open, on_save, on_cancel)
var display_element = this.display_elements[index]; var display_element = this.display_elements[index];
var edit_element = this.edit_elements[index]; var edit_element = this.edit_elements[index];
if (display_element.dataset.editorEmptyText !== undefined && edit_element.value == "")
{
display_element.innerText = display_element.dataset.editorEmptyText;
}
else
{
display_element.innerText = edit_element.value; display_element.innerText = edit_element.value;
} }
}
this.close(); this.close();
}; };