qml: Clear saved password using onPressed handler

Using onTextEdited meant that the clear() call would happen after the edit had actually happened.

Instead, use the Keys.onPressed handler, which happens earlier in the input chain.
This commit is contained in:
Tom Dewey 2023-12-15 13:15:19 +00:00 committed by Tom Dewey
parent d19c7599f7
commit 9b15f7909b

View file

@ -153,19 +153,26 @@ Window {
}
TextField {
id: fieldUserPassword
echoMode: TextInput.Password
echoMode: TextInput.PasswordEchoOnEdit
Layout.minimumWidth: 200
selectByMouse: true
property bool alreadyCrypted: false
property bool indicateError: false
onTextEdited: {
Keys.onPressed: (event)=> {
if (alreadyCrypted) {
/* User is trying to edit saved
(crypted) password, clear field */
alreadyCrypted = false
clear()
}
// Do not mark the event as accepted, so that it may
// propagate down to the underlying TextField.
event.accepted = false
}
onTextEdited: {
if (indicateError) {
indicateError = false
}