Page 1 of 2

Abort GUI 'OK' click due to validation of form input

Posted: Fri Aug 31, 2018 3:55 pm
by laned101
Im carrying out validation in the `$buttonOK_Click` block and if theres an error, it should prompt (this it does). Once clicking 'OK' on the error you should be able to modify input before submitting again.

However Im not entirely sure how to exit the block to stop the form closinging and to stop the main() continueing. Ive tried using a break, returns and even tried the same breakout attempt in the main() form but with no luck.

Any help would be apprecaited.

https://ibb.co/hWRBXz
Image

***Code Block***
https://ibb.co/nQJfQK
Image

Re: Abort GUI 'OK' click due to validation of form input

Posted: Fri Aug 31, 2018 4:03 pm
by jvierra
Set "$_.Cancel = $true" In the "Closing" event. The validations should be in the "Closing" or in the validation events.

Re: Abort GUI 'OK' click due to validation of form input

Posted: Fri Aug 31, 2018 5:25 pm
by laned101
Thanks for the prompt response however, I dont see a closing event function etc?

Re: Abort GUI 'OK' click due to validation of form input

Posted: Fri Aug 31, 2018 6:37 pm
by jvierra
Just look at the events list under the form. It is called "FormClosing" and is in the "Behavior" group.

See: https://info.sapien.com/index.php/guis/ ... rm-control

Re: Abort GUI 'OK' click due to validation of form input

Posted: Sat Sep 01, 2018 10:17 am
by laned101
I dont see that event on the form event list. Maybe because I dont have a cancel button?

https://ibb.co/gPifue

Re: Abort GUI 'OK' click due to validation of form input

Posted: Sat Sep 01, 2018 11:14 am
by jvierra
You won't see it until you add it.
Look up how to add events in the manual. There are a number of ways to do this. THe easiest is to right click on the form and select Add Events".

Re: Abort GUI 'OK' click due to validation of form input

Posted: Sat Sep 01, 2018 12:00 pm
by laned101
Arrr I see! Thank you, out of curiousity is there something to identify if the X to close the window is pressed? As im doing validation checks in the closing event I get validation failures if I close the form on the X too. So the form doenst close on the X press

Re: Abort GUI 'OK' click due to validation of form input

Posted: Sat Sep 01, 2018 12:20 pm
by jvierra
The closing event will fire.
If you don't want to deal with this remove the "X" from the form.

Re: Abort GUI 'OK' click due to validation of form input

Posted: Sat Sep 01, 2018 2:25 pm
by laned101
Do you have a recommended way to handle the validation with regards to the location it runs? On OKclick event etc?

Re: Abort GUI 'OK' click due to validation of form input

Posted: Sat Sep 01, 2018 2:30 pm
by jvierra
Validation only runs in validation events. You seem to be missing how events work.

There are a great may articles that describe various approaches to validation. We have to design a validation mechanism that applies to the task we are performing and the event structure of forms.