Expand my Community achievements bar.

Don’t miss the AEM Skill Exchange in SF on Nov 14—hear from industry leaders, learn best practices, and enhance your AEM strategy with practical tips.
SOLVED

Have to click on the button twice to execute code on Click event.

Avatar

Former Community Member

I have a button that has following code on the click event.
_SubFormS.setInstances(0);

Last week I added following code on the Exit event of the button.
xfa.host.setFocus(Subf.ButtonRemove);

For some reason, I have to click twice to set instance to 0. It never happened before. If I comment out code on Exit even, nothing changes. Any ideas for this bizarre behaviour.

Thank you.

1 Accepted Solution

Avatar

Correct answer by
Level 4

Hey 1996,

It sounds to me like you have a setfocus soomehwere that is still overriding the click event. For example, if you have a field that doesn't check if (xfa.event.commitKey == 3) before setFocus is called, it doesn't matter which other field (or button) you click on, you will be sent to the field specified by the setFocus. "Double clicking" isn't a double click, it's one click which is overridden by a setFocus (which sends you somewhere else) then a second click which isn't interrupted by a setfocus, which means that you can click the button.

I don't think that I've explained myself well, so here is step-by-step what I think is happening:

- You are currently in a field that just has a setFocus without checking the commitKey.

- You click on the button.

- Due to the setFocus, you are sent to a different field that is not the button. This means that the button never fires teh click event. the second field that you are sent to has the proper commitKey checks.

- You click on the button again,

- This time, because the new field you are in has the proper commitKey check, you are not sent to another field, and your click succeeds.

I hope that did a good job of explaining my guess as to what is happening. Check all of your exit events to make sure that they are all using the if (xfa.event.commitKey == 3) then bit. having forgotten one would explain why this doesn't happen all the time... it's only happening when you try to click the button while you are in the field wihtout the commitKey check.

Let me know if that helps,

- Scott

View solution in original post

7 Replies

Avatar

Former Community Member


It looks like my issue is related to the code on the previous button. Button1 has a code on exit even that will set a focus to Button2 ( the one that I have to double click to execute Click event).
Can I need to force the tabbing order and keep my code on the click event.

Does anyone have any suggestion?

Button1:
On Click:
_SubFormS.setInstances(1);
  xfa.layout.relayout();
OnExit
xfa.host.setFocus(Button2);

Button2:
_SubFormS.setInstances(0);

OnExit
xfa.host.setFocus(Subf.ButtonRemove);

Avatar

Former Community Member

past-tens once suggested this code on exit event but it needs to be in calc script. it works now.

 

if  (xfa.event.commitKey == 3) then

xfa.host.setFocus(Button2);

endif

Thanks Past-tens.

Avatar

Level 10

I wonder if it could be something to do with the order of operations when dealing with enter/exit/click etc.

I figured out the order of operations for using the mouse on a button but not tabbing/setFocus/enter/exit.

The order I found was:

mouseEnter

mouseDown

enter

mouseUp

click

mouseExit

Avatar

Level 10

...followed lastly by the button's exit event

Avatar

Former Community Member

I've spoken to fast. Issue still exists, but only when I used mouse and not all the time. It does not happen when I initially click on the button. It happens if I come back to the button, after I am done some other operations like entering data in some fields, clicking on the other buttons,etc.

Avatar

Correct answer by
Level 4

Hey 1996,

It sounds to me like you have a setfocus soomehwere that is still overriding the click event. For example, if you have a field that doesn't check if (xfa.event.commitKey == 3) before setFocus is called, it doesn't matter which other field (or button) you click on, you will be sent to the field specified by the setFocus. "Double clicking" isn't a double click, it's one click which is overridden by a setFocus (which sends you somewhere else) then a second click which isn't interrupted by a setfocus, which means that you can click the button.

I don't think that I've explained myself well, so here is step-by-step what I think is happening:

- You are currently in a field that just has a setFocus without checking the commitKey.

- You click on the button.

- Due to the setFocus, you are sent to a different field that is not the button. This means that the button never fires teh click event. the second field that you are sent to has the proper commitKey checks.

- You click on the button again,

- This time, because the new field you are in has the proper commitKey check, you are not sent to another field, and your click succeeds.

I hope that did a good job of explaining my guess as to what is happening. Check all of your exit events to make sure that they are all using the if (xfa.event.commitKey == 3) then bit. having forgotten one would explain why this doesn't happen all the time... it's only happening when you try to click the button while you are in the field wihtout the commitKey check.

Let me know if that helps,

- Scott

Avatar

Former Community Member

Past-tens,

Once again you made my day .Thank you.

I've missed to put  if (xfa.event.commitKey == 3) then on the button that was next in the tabbbing order.Once I put the code, it fixed the issue and it is working as expected. I actually had xfa.host.setFocus(Button3), but that wasn't enough.

You explained it very well.

Thank you so much!