closing the form using ESC button


I know that on clicking the esc button the form will call for close method and if we write any validation in canclose and the form will not allow user to close the form until the validation gets filled as the canclose method will gets called first to close method.

So my question is,is there a way i can write the validation in canclose and user should be able to close the form using esc button eventhough the validation in canclose method doesn’t gets filled?Please let me know.

Thanks for your help!!!

Hello Dasaradh,

can you please specify at what stage you want to execute that validation then?

hi Kunal,

I want to execute the validation when user closes a form even the user won’t edit anything on form,But user wants to close the form if he clicks ESC button.let me know if i’m not clear to you

sorry Dasaradh,

it is still not clear for me, you mean you want to differentiate esc button and manually close by clicking on close button?

i have validation in canClose() method of the form. In this method I can do validation the value. If it’s not set then I need to return false. So the form will not able to be close even though by clicking ESC button. So here I want to close the form by using ESC button,is there a way we can do this through code?

Hello Dasaradh,

you can achieve it thru task method

i just make one example , please test it by ur side as well

declare 1 integer in class declaration

int esc;

override task() on form and assign value of _taskId argument to new variable

public int task(int _taskId)


int ret;

ret = super(_taskId);

esc = _taskId;

return ret;


use this variable in canclose() to filter the code

public boolean canClose()



boolean ret;

ret = super();

ret = false;



ret = true;


return ret;