Ivan Fateev
Ivan Fateev

Reputation: 1061

Clear TextField in QML on Android

I have a simple textfield:

TextField {
       id: searchField
       height: Units.dp * 40
       color: Palette.colors["white"]["500"]
       textColor: Palette.colors["white"]["500"]
       placeholderText: qsTr("Search...")

}

And I'm trying to clear TextField input as following:

function clearSearch() {
    Qt.inputMethod.reset()
    Qt.inputMethod.hide()
    searchField.focus = false
    searchField.text = ""
}

It seems that on Android function clearSearch doesn't work. What I see that text input still contains last entered text (I guess it is a displayText). Also I suppose that it is due autocomplete feature of the keyboard.

Am I clearing a text input the wrong way?

My test case:

  1. Enter something in the field, using virtual keyboard with autocomplete.
  2. Do not confirm input, leaving current word selected (underlined)
  3. Tap clear button (call to clearSearch())
  4. Notice that there is still an underlined text in a TextField
  5. Tap on a field again, and see that keyboard shows again, and text field is empty now

P.S. Qt 5.5

Upvotes: 3

Views: 3007

Answers (1)

jpnurmi
jpnurmi

Reputation: 5836

You can call Qt.inputMethod.reset() to reset any partial uncommitted text input from an input method.

Upvotes: 3

Related Questions