hide a field when clicking/tapping outside of it

Got a LiveCode personal license? Are you a beginner, hobbyist or educator that's new to LiveCode? This forum is the place to go for help getting started. Welcome!

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller

Post Reply
keram
Posts: 340
Joined: Fri Nov 08, 2013 4:22 am

hide a field when clicking/tapping outside of it

Post by keram » Tue May 06, 2014 11:22 am

Hi,

I have card with number of buttons labels and fields. One of the fields is for selection of fonts (fld "fonts"). When clicking or tapping on it fonts are selected and the field gets hidden. I'd like to make it possible to hide that field with click/tap outside of it.

I grouped all the objects (except the font field) on that card (grp "settingsGroup") and put the code below on the group level

Code: Select all

on mouseUp
   put the effective rect of fld "fonts" into tHideFonts
   if the mouseH < item 1 of tHideFonts or the mouseH > item 3 of tHideFonts \ 
         or the mouseV < item 2 of tHideFonts or the mouseV > item 4 of tHideFonts then hide fld "fonts"
end mouseUp
+ this code on the card level

Code: Select all

on mouseUp
   send mouseUp to grp "settingsGroup"
end mouseUp
then it works except for the buttons on the card.

I could put the same code in each button on the card, but would prefer to make it with least coding, preferably on one place.

How to make it?

keram
Using the latest stable version of LC Community 6.7.x on Win 7 Home Premium, 64bit

jmburnod
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 2729
Joined: Sat Dec 22, 2007 5:35 pm
Contact:

Re: hide a field when clicking/tapping outside of it

Post by jmburnod » Tue May 06, 2014 11:46 am

Hi Keram
it works except for the buttons on the card.
Mouserelease ?
https://alternatic.ch

keram
Posts: 340
Joined: Fri Nov 08, 2013 4:22 am

Re: hide a field when clicking/tapping outside of it

Post by keram » Tue May 06, 2014 12:33 pm

Hi Jean-Marc,

From Dictionary about mouseRelease: "Sent when the user releases the mouse outside the control that was clicked."
So that requires a tap/click on the fld "fonts" to start with and that's what I want to avoid. The user should be able to tap outside the field to hide it.

Thanks anyway.

keram
Using the latest stable version of LC Community 6.7.x on Win 7 Home Premium, 64bit

Klaus
Posts: 14199
Joined: Sat Apr 08, 2006 8:41 am
Contact:

Re: hide a field when clicking/tapping outside of it

Post by Klaus » Tue May 06, 2014 12:52 pm

Hi Keram,

do the buttons in your group have a "mouseup" handler on their own?
If yes, you need to add "pass mouseup" at the end of that handler.


Best

Klaus

keram
Posts: 340
Joined: Fri Nov 08, 2013 4:22 am

Re: hide a field when clicking/tapping outside of it

Post by keram » Tue May 06, 2014 5:49 pm

Thanks Klaus,

Yes, they do. In some cases that addition of "pass mouseUp" helped. This is in cases where the handler puts in a text into a field for example. But in cases where there is are command go or answer it does not work. But it's not a big deal, there are just few of these buttons and I can code them individually with this:

Code: Select all

      if  visible of fld "fonts" of cd "settingsandfiles" is true then
      put the effective rect of fld "fonts" into tHideFonts
      if the mouseH < item 1 of tHideFonts or the mouseH > item 3 of tHideFonts \ 
            or the mouseV < item 2 of tHideFonts or the mouseV > item 4 of tHideFonts then hide fld "fonts"
      exit mouseUp to top
   end if
keram
Using the latest stable version of LC Community 6.7.x on Win 7 Home Premium, 64bit

Klaus
Posts: 14199
Joined: Sat Apr 08, 2006 8:41 am
Contact:

Re: hide a field when clicking/tapping outside of it

Post by Klaus » Tue May 06, 2014 5:56 pm

Hi Keram,

Code: Select all

exit mouseUp to top
Either:
exit mouseup
or
exit to top
:D


Best

Klaus

keram
Posts: 340
Joined: Fri Nov 08, 2013 4:22 am

Re: hide a field when clicking/tapping outside of it

Post by keram » Tue May 06, 2014 7:33 pm

Thanks,
I was overzealous to really exit :)
Using the latest stable version of LC Community 6.7.x on Win 7 Home Premium, 64bit

Klaus
Posts: 14199
Joined: Sat Apr 08, 2006 8:41 am
Contact:

Re: hide a field when clicking/tapping outside of it

Post by Klaus » Tue May 06, 2014 7:39 pm

keram wrote:Thanks,
I was overzealous to really exit :)
:D :D :D

Post Reply