Dialog shouldn't be closed automatically when OK is pressed
-
Hello,
my dialog accepts input in 2 TextFields. When the user presses OK, I check if the input in the TextFields is equal. If not the dialog shouldn't be closed. How can I do this?
import QtQuick 2.3
import QtQuick.Controls 1.3
import QtQuick.Dialogs 1.2Dialog {
id: dialogVirtualKeyboard
standardButtons: StandardButton.Ok | StandardButton.CancelMessageDialog { id: passwordMessage text: "Passwords must be equal!" onAccepted: dialogVirtualKeyboard.open() } onAccepted: { if (inputText.text != inputTextRepeat.text) passwordMessage.open() } TextField { id: inputText height: 25; width: parent.width } TextField { id: inputTextRepeat height: 25; width: parent.width }
}
Any help is highly appreciated!
Christine
-
Have you tried calling open() from onAccepted? I don't know if that will work.
It doesn't seem like a very friendly UI: the user clicks ok, and then nothing happens? How do they know what's wrong? You could open another dialog telling them what's wrong, and from that dialog, re-open the first dialog.
-
I just changed my source code according to your suggestion. When the texts are not equal I open a MessageDialog in onAccepted (but the original dialog is already closed) and when this is closed I open the original dialog again. But that's not what I want.
The original dialog should stay open when the MessageDialog is shown. I can't believe that this isn't possible.
-
Yes I did. But I also have to open my MessageBox in onAccepted and then input is allowed in both dialogs at the same time.