Correct way to structure data validation and main window destroy method

This forum can be used to talk about general design strategies, new ideas and questions in general related to wxWidgets. If you feel your questions doesn't fit anywhere, put it here.
Post Reply
henrylaw
In need of some credit
In need of some credit
Posts: 6
Joined: Wed Jan 24, 2018 8:43 pm

Correct way to structure data validation and main window destroy method

Post by henrylaw »

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]
User avatar
doublemax
Moderator
Moderator
Posts: 19103
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: Correct way to structure data validation and main window destroy method

Post by doublemax »

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.
Use the source, Luke!
henrylaw
In need of some credit
In need of some credit
Posts: 6
Joined: Wed Jan 24, 2018 8:43 pm

Re: Correct way to structure data validation and main window destroy method

Post by henrylaw »

OK, I'll try that. Thank you.
Post Reply