Skip to content

Commit

Permalink
update undef state
Browse files Browse the repository at this point in the history
Signed-off-by: Mark Herwege <[email protected]>
  • Loading branch information
mherwege committed Apr 3, 2023
1 parent e537923 commit ccd4d5f
Showing 1 changed file with 29 additions and 11 deletions.
40 changes: 29 additions & 11 deletions bundles/org.openhab.ui.basic/web-src/smarthome.js
Original file line number Diff line number Diff line change
Expand Up @@ -1537,6 +1537,7 @@

var
lastValue = _t.input.value,
lastUndef = _t.input.nextElementSibling.innerHTML.trim(),
numberPattern = /^(\+|-)?[0-9\.,]+/,
timePattern = /^[0-9]{2}:[0-9]{2}/,
dotSeparatorPattern = /^-?(([0-9]{1,3}(,[0-9]{3})*)|([0-9]*))?(\.[0-9]+)?$/,
Expand Down Expand Up @@ -1624,25 +1625,41 @@
}

_t.setValuePrivate = function(value, itemState) {
var state = (itemState === "undefined" || itemState === "UNDEF" || itemState === "NULL") ? "" : itemState;

if (_t.verify) {
_t.verify.cancel();
}

var newValue = value ? value : state;
var newValue = value;
var undefValue = "";
if (itemState === undefined) {
undefValue = lastUndef;
} else if (itemState === "NULL" || itemState === "UNDEF") {
newValue = "";
undefValue = (value !== "") ? value : lastUndef;
}

if (_t.inputHint === "number") {
newValue = parseNumber(newValue).value;
var valueArray = newValue.trim().split(" ");
if (valueArray.length > 0) {
newValue = valueArray[0];
}
if (valueArray.length > 1) {
_t.input.parentNode.nextElementSibling.innerHTML = valueArray[1];
if (newValue !== "") {
newValue = parseNumber(newValue).value;
var valueArray = newValue.trim().split(" ");
if (valueArray.length > 0) {
newValue = valueArray[0];
}
if (valueArray.length > 1) {
_t.input.parentNode.nextElementSibling.innerHTML = valueArray[1];
}
} else {
var undefArray = undefValue.split(" ");
if (undefArray.length > 0) {
undefValue = undefArray[0];
}
}
} else if (_t.itemType === "datetime") {
if (_t.inputHint) {
newValue = state ? state : value;
newValue = (itemState !== undefined) ? itemState : value;
undefValue = "";
} else {
undefValue = "YYYY-MM-DD hh:mm:ss";
}
newValue = newValue.trim().split(".")[0];
if (_t.inputHint === "date") {
Expand All @@ -1655,6 +1672,7 @@
}
}
_t.input.value = newValue;
_t.input.nextElementSibling.innerHTML = undefValue;

_t.input.parentNode.MaterialTextfield.change();
_t.input.parentNode.MaterialTextfield.checkValidity();
Expand Down

0 comments on commit ccd4d5f

Please sign in to comment.