p

    paoloconte

    6 months ago
    Hello, I'm a bit confused on how to clear a Text Input.. let's say I have
    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
    hfhbd

    hfhbd

    6 months ago
    You are using uncontrolled inputs and should call
    value(text)
    p

    paoloconte

    6 months ago
    No, I want to edit the text, with value the text is not editable
    hfhbd

    hfhbd

    6 months ago
    It is, if you use onInput:
    var text by remember { mutableStateOf("InitValue") }
    Input(type = InputType.Text) {
      value(text)
      placeholder("Username")
      onInput {
        text = it.value
      }
    }
    p

    paoloconte

    6 months ago
    Of course! I was using
    onChange
    instead of
    onInput
    , that's why... thanks @hfhbd