I want to be able to get the value of lightning-input when the user input is invalid.
From the lightning-input documentation:
For input type number, the component sets the value to '' (an empty string) when the number input becomes invalid. The change event is fired each time the value changes, even when the value is set to an empty string. This enables you to reset the field in your onchange handler when input is invalid. Use separate variables to set the value of the number input and retrieve it.
Is there a way to get the value even if it is deemed invalid?
For example: test.html
<template>
<lightning-input formatter="currency" onchange={handleChange}></lightning-input>
</template>
test.js:
export default class test extends lightningElement {
handleChange(event) {
console.log(event.target.value) // prints the empty string on invalid input
}
}
If I paste "potato" into the input box, event.target.value
will be the empty string. Is there a way to get the actual value? I have tried other event handlers (onblur
, oncommit
, and on invalid
) as well as using the querySelector
to no avail.
Thanks in advance!