ExitField / CloseField do nothing when a user clicks on a button straight from a field

Anything beyond the basics in using the LiveCode language. Share your handlers, functions and magic here.

Moderators: Klaus, FourthWorld, heatherlaine, robinmiller, kevinmiller

Post Reply
mrcoollion
Posts: 417
Joined: Thu Sep 11, 2014 1:49 pm
Location: The Netherlands

ExitField / CloseField do nothing when a user clicks on a button straight from a field

Post by mrcoollion » Wed Dec 04, 2019 10:04 am

Hi experts,

This is an old problem i cannot seem to solve.
I need to do some actions as soon as a user left a field (by clicking onto another field or on a button or outside the app ect...).
If a user after entering data into the field exits a field by clicking on another field the 'on ExitField' handler works fine.
However when a user after entering data into the field clicks on a button the 'on ExitField' is not triggered, neither are the 'on closefield' and the 'on focusout' handlers. This is probably because the cursor stays (blinking) in the field and therefore no handler is triggered?

These are all the handler i know that could/should solve this but none reacts when a user clicks on a button straight from the field.
I cannot use 'on rawkey...' because this triggers the 'DoFieldActions' handler each time a user enters a letter and that is to much!

Code: Select all

on closeField 
   DoFieldActions
end closeField
--
on exitField
   DoFieldActions
end exitField
--
on focusOut
   DoFieldActions
end focusOut
The only thing that does work is if I place the following code in the button to force LC to change the focus from field to button and then the 'on closeField ' handler is activated.

Code: Select all

set the traversalOn of me to true
   focus on me
Any ideas how to solve this from within the field ?

Regards,

Paul
Last edited by mrcoollion on Wed Dec 04, 2019 10:39 am, edited 1 time in total.

[-hh]
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 2182
Joined: Thu Feb 28, 2013 11:52 pm
Location: Göttingen, DE

Re: ExitField / CloseField do nothing when a user clicks on a button straight from a field

Post by [-hh] » Wed Dec 04, 2019 10:24 am

You could try on textchanged.
shiftLock happens

mrcoollion
Posts: 417
Joined: Thu Sep 11, 2014 1:49 pm
Location: The Netherlands

Re: ExitField / CloseField do nothing when a user clicks on a button straight from a field

Post by mrcoollion » Wed Dec 04, 2019 10:43 am

[-hh] wrote:
Wed Dec 04, 2019 10:24 am
You could try on textchanged.
Tried this but 'on textchanged' triggers on each change in the field , this is to much :-(

But thanks though :-)

bogs
Posts: 3995
Joined: Sat Feb 25, 2017 10:45 pm

Re: ExitField / CloseField do nothing when a user clicks on a button straight from a field

Post by bogs » Wed Dec 04, 2019 10:50 am

mrcoollion wrote:
Wed Dec 04, 2019 10:04 am
when a user after entering data into the field clicks on a button the 'on ExitField' is not triggered, neither are the 'on closefield' and the 'on focusout' handlers.
The first thought that came to me was similar to your focus change, if you know you want something to happen or you need (something from the field) on the button click, create a handler and launch it in the first line of the button click or, if the code is short enough, just put it as the first few lines of the button handler.

Otherwise, if your just looking for changes in the field, text changed works, stuffing the field into a variable at the beginning/end works, etc. as Hermann says. You can see a variation of these techniques here. You'll notice that I compare the current field to the contents in the variable, when xxx number of characters are different, it triggers the prompt to save.
Image

mrcoollion
Posts: 417
Joined: Thu Sep 11, 2014 1:49 pm
Location: The Netherlands

Re: ExitField / CloseField do nothing when a user clicks on a button straight from a field

Post by mrcoollion » Wed Dec 04, 2019 11:31 am

Thanks for the lesson bogs :D ,

For now i opted for the 'focus change' option. This is the easiest way to achieve my goals.

Regards,

Paul

Klaus
Posts: 11313
Joined: Sat Apr 08, 2006 8:41 am
Location: Germany
Contact:

Re: ExitField / CloseField do nothing when a user clicks on a button straight from a field

Post by Klaus » Wed Dec 04, 2019 11:36 am

Hi Paul,

I had a similar problem on my Mac. On the Mac "traveralon" does not seem to work all the times in a button,
means does NOT remove focus from other objects as it should.
I did:

Code: Select all

on mouseup
  ## FORCE close/exitfield or whatever
  focus on nothing
  ## my mouseup stuff here...
end mouseup
Best

Klaus

mrcoollion
Posts: 417
Joined: Thu Sep 11, 2014 1:49 pm
Location: The Netherlands

Re: ExitField / CloseField do nothing when a user clicks on a button straight from a field

Post by mrcoollion » Wed Dec 04, 2019 2:29 pm

Thanks Klaus,

That is even shorter and it works :D

Post Reply

Return to “Talking LiveCode”