Fix input text behavior for null/empty value fields

This commit is contained in:
Saba 2021-12-04 10:45:48 -05:00
parent e068968b35
commit 2490e72df5

View file

@ -88,7 +88,7 @@ function makeElementEditable(original, data, key) {
var inputNewText = document.createElement("input"); var inputNewText = document.createElement("input");
inputNewText.type = "text"; inputNewText.type = "text";
inputNewText.className = "config-element-edit"; inputNewText.className = "config-element-edit";
inputNewText.value = original.textContent; inputNewText.value = (original.textContent == emptyValueDefault) ? "" : original.textContent;
fixInputOnFocusOut(inputNewText, data, key); fixInputOnFocusOut(inputNewText, data, key);
original.parentNode.replaceChild(inputNewText, original); original.parentNode.replaceChild(inputNewText, original);
inputNewText.focus(); inputNewText.focus();
@ -118,7 +118,7 @@ function createValueNode(data, key) {
*/ */
function fixInputOnFocusOut(original, data, key) { function fixInputOnFocusOut(original, data, key) {
original.addEventListener("blur", () => { original.addEventListener("blur", () => {
data[key] = (!!data[key] && original.value != emptyValueDefault) ? original.value : ""; data[key] = (original.value != emptyValueDefault) ? original.value : "";
original.parentNode.replaceChild(createValueNode(data, key), original); original.parentNode.replaceChild(createValueNode(data, key), original);
}) })
} }