Hello, I'm a bit confused on how to clear a Text Input.. let's say I have
Copy code
var text by remember { mutableStateOf("") }
Input(type = InputType.Text, attrs = {
defaultValue(text)
onChange { event ->
text = event.target.value
}
})
If I then set
text = ""
the input field is not cleared, as defaultValue is not reapplied... so how can I clear it? is the only way using a reference to the HTMLInputElement?
Thanks
h
hfhbd
03/17/2022, 1:48 PM
You are using uncontrolled inputs and should call
value(text)
p
paoloconte
03/17/2022, 1:51 PM
No, I want to edit the text, with value the text is not editable
h
hfhbd
03/17/2022, 2:08 PM
It is, if you use `onInput`:
Copy code
var text by remember { mutableStateOf("InitValue") }
Input(type = InputType.Text) {
value(text)
placeholder("Username")
onInput {
text = it.value
}
}