Hello, I'm a bit confused on how to clear a Text I...
# compose-web
p
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
You are using uncontrolled inputs and should call
value(text)
p
No, I want to edit the text, with value the text is not editable
h
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
  }
}
p
Of course! I was using
onChange
instead of
onInput
, that's why... thanks @hfhbd