Notifications
Announcements
No record found.
Hello everyone,
I have an OKCancel dialog form. I have a combox with different enum values on the form on user's choice and several field controls not bound to the datasource which user has to fill up. Is there any best practice of how to validate field controls upon OK button press? Validate() methods doesn't fit because it only works when user modifies the field. If he doesn't fill up field with any value and just press OK then validate() method on the form control won't work. I have tried to search any method on the form but there is no anything suitable.
Can you please point me to the right diresction?
Thanks
What about canClose() or close()?
Maybe canClose looks ok) Read a description on Microsoft
Specifies whether you can close the form. The call to super in the method checks whether closing the form is a valid action.
The canClose method is started by the closeCancel or the closeOK methods.
Use this method to add your own checks that determine whether the form should close.
but I need my form not to be closed if the values are invalid and proceed popping up those warning messages until either they are ok or user presses Cancel. Would it be ok? Anyway I'll try) Thanks a lot!
public boolean canClose() { boolean ret; ret = super(); if(this.closedOk()) { if(ChangeDates.selection() == 0) { if(!ChangeYear.value()) { ret = checkFailed("Значение поле год не должно быть пустым!"); } } else if(ChangeDates.selection() == 1) { if(!PlannedDate.dateTimeValue() || !FinishPlannedDate.dateTimeValue()) { ret = checkFailed('Поля "Спланированное начало" и "Запланированная дата окончания" должны быть заполнены!'); } } } return ret; }
Wrote this but for some unknown reason it goes further to cloeOK(). even though ret is false
If "it goes further to cloeOK()" means that after completing the method, execution is returned back to to the method that called canClose(), then it's all right. If you call canClose() method, you want to get a value, either true or false, and then you'll do something with the value.
It's said here
dhruvrthakar.wordpress.com/.../
Finally, CanClose() is called before any of the close methods get called. If CanClose() returns false, the form is not allowed to close.
Doesn't it mean that if canClose() returns false the execution of the form has to be interrupted? Otherwise what's the point of using canClose()? Ok. I get false from canClose(). Canclose() is called in super() of closeOK(). Then execution proceeds back to closeOK(). I need form not to be closed and show an error until user enters valid values. How to achieve that?
I thought if canClose() returns false AX automatically interrupts closeOK() method execution? Aren't I right?
Thank you.
Can you please create a new form, override canClose() to always return false, build the project, open the form and try to close it? Does it prevent closing? If so, the standard logic works correctly and you have some kind of bug in your form. You mentioned returning to closeOk() - haven't you overridden it with wrong code?
Under review
Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.
As AI tools become more common, we’re introducing a Responsible AI Use…
We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…
These are the community rock stars!
Stay up to date on forum activity by subscribing.
Martin Dráb 565 Most Valuable Professional
André Arnaud de Cal... 450 Super User 2025 Season 2
Sohaib Cheema 250 User Group Leader