I have what I think is a design problem, rather than one that involves specific code. It relates to the order in which events are handled. My own environment is listed at the end, in case it matters.
I have a text field in which a user is to enter a date. There is a validation routine which checks for a valid date; if it finds an error it puts up a message box and sets the focus to the text field for the user to modify. The text field itself invokes the validation routine via the EVT_KILL_FOCUS handler.
The main window has a "Cancel" button, which simply invokes its Destroy method.
The problem: if the date text field is invalid, pressing the "Cancel" button causes the EVT_KILL_FOCUS event to fire first, so the validator puts its error message up and the Destroy method isn't invoked; the user is in a loop until a valid value is put in the date field. I want the "Cancel" button to over-ride everything and just close.
I've verified from some diagnostic messages that the EVT_KILL_FOCUS event is happening before the click to the cancel button; so I can't do anything funky like setting a global flag value in the "cancel" button which I can then use to disable the date validation.
What's the right way to structure this code?
[I'm actually developing under Perl 5.34.0, wxwidgets 3.0 and libwx-perl 1:0.9932-6build1; Linux Mint 21]
Correct way to structure data validation and main window destroy method
Re: Correct way to structure data validation and main window destroy method
As a user, i hate when a validation fails and it shows a modal dialog that i have to close first before i can continue.
I would suggest to use wxRichToolTip to show the message to the user (it it's implemented in wxPerl). And that should also solve your problem with the cancel button.
I would suggest to use wxRichToolTip to show the message to the user (it it's implemented in wxPerl). And that should also solve your problem with the cancel button.
Use the source, Luke!
Re: Correct way to structure data validation and main window destroy method
OK, I'll try that. Thank you.