PDA

View Full Version : Trying to get a stringfield to lose focus.



MooCow
January 7th, 2020, 21:48
I've figured out that I should use the Escape key to make a control lose focus, but I still don't understand why this piece of code wouldn't work:



<script>
function onClickDown(nButton, _, _)
if nButton == 1 then
if hasFocus() == true then
setFocus(false);
end
end
end
</script>


Have I typed it wrong? It feels like setFocus() isn't even working here.

Moon Wizard
January 7th, 2020, 22:34
Ruleset scripts are processed before standard processing. So, the focus isn’t set until after your script returns.

If you don’t want the standard processing to occur after your script, you need to “return true”.

Also, if you just want to block UI interaction, then use readonly or disabled tags.

Regards,
JPG

MooCow
January 7th, 2020, 22:55
Ruleset scripts are processed before standard processing. So, the focus isn’t set until after your script returns.

If you don’t want the standard processing to occur after your script, you need to “return true”.

Also, if you just want to block UI interaction, then use readonly or disabled tags.

Regards,
JPG

No, my code wasn't meant to block interaction. I figured that I click once to set the focus, then type something in the field, and then click once more to unfocus it, since I can't use Enter to finish.
...but maybe the "standard processing" you mentioned, then quickly refocuses the field again. Maybe "return true" would have prevented that, if i understood you correctly. Thank you.