Good point @Saif, those characters should be valid. I completely missed it. 2e10
, -2e4
, -10e+2
are all valid number representations.
fwChange
gets triggered with an empty value in the event payload’s target.value
. Also, the value
property of the DOM element goes empty. So in this case, this happens when the number is invalid. For example:
-
2e
is an invalid number, so, fwChange
triggers with target.value
as an empty string.
-
2e10
is a valid number, so fwChange
triggers with target.value
as a number string.
The type of the value is always string
. The correct way to parse this will then be to use parseFloat(event.target.value)
.
<fw-input
id="input-num"
label="Num"
type="number"
></fw-input>
const inputNum = document.getElementById("input-num");
inputNum.addEventListener("fwChange", function (evt) {
// String representation. Will be empty string when invalid number is input
console.log(evt.target.value);
// Parsed number. Will be NaN when invalid number is input
console.log(parseFloat(evt.target.value));
});
Which makes this a documentation gap.