Struggling Handling Focus of 1 field

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

doobox
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 284
Joined: Tue May 24, 2011 11:47 pm

Struggling Handling Focus of 1 field

Post by doobox » Tue Jul 17, 2012 10:57 am

Hi there,

I have a palette stack with 1 entry field(userEmailAddress) and 1 drop-down select(checkInterval).

When the stack opens i don't want anything focused.!

easy:

Code: Select all

on openStack
focus on nothing
end openStack

on resumeStack
focus on nothing
end resumeStack
So i can focus on the entry field fine. But i cant lose the focus when clicking away, or selecting the dropdown list object.
There does not seem to be any message related to the field when clicking away after it has been focused.
I have tried all kinds of crazy handlers like on the card:

Code: Select all

on mouseUp
   if not (word 2 of the target is "userEmailAddress") then
      focus on nothing
   end if
end mouseUp
This is heading in one right direction, but unveils many more handlers would be needed to cover many other possible user actions.
I am sure there is a really simple way to handle this, as fields would be mixed with other controls in most cases for collecting user input, but for the life of me i cant see it.

Kind regards
Gary
Kind Regards
Gary

https://www.doobox.co.uk

Dixie
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 1336
Joined: Sun Jul 12, 2009 10:53 am

Re: Struggling Handling Focus of 1 field

Post by Dixie » Tue Jul 17, 2012 11:54 am

Gary...

Would...

Code: Select all

on mouseLeave
    focus on nothing
end mouseLeave
help at all ?

be well

Dixie

doobox
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 284
Joined: Tue May 24, 2011 11:47 pm

Re: Struggling Handling Focus of 1 field

Post by doobox » Tue Jul 17, 2012 11:59 am

Thanx Dixie, But i dont think that will be suitable really.
That would give a really odd behavior.

If the user clicked in and got focus, just before they were about to start typing, there cursor left the field, they would need to click back in.
Kind Regards
Gary

https://www.doobox.co.uk

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10305
Joined: Wed May 06, 2009 2:28 pm

Re: Struggling Handling Focus of 1 field

Post by dunbarx » Wed Jul 18, 2012 2:14 am

Not sure I completely understand, but how about "closeField, "focusOut" or "exitField"?

Craig Newman

LittleGreyMan
Posts: 49
Joined: Sat Jun 16, 2012 7:57 pm

Re: Struggling Handling Focus of 1 field

Post by LittleGreyMan » Wed Jul 18, 2012 9:03 am

Hi,

As Craig, not sure I understand what you're trying to achieve.

But if it's just a display issue, did you try scripting the showFocusBorder of the field instead of controlling the focus?
Best regards,

Didier

doobox
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 284
Joined: Tue May 24, 2011 11:47 pm

Re: Struggling Handling Focus of 1 field

Post by doobox » Wed Jul 18, 2012 9:13 am

If i palette a substack that has just 1 card, 1 text field, and 1 dropdown select.

Without any additional coding or amendment to the objects properties.
The field gets focus on opening... "normal and expected".. but on clicking away from the field
there is no message sent : closeField, exitField, or focusOut.

I must have done something in another stack, card or object, outside this new substack. Because if i test this with a new test project, this behavior is not seen.
And i do see a message on clicking away from the field.
I am obviously catching the messages somewhere. urghh..

So if i have an on exitField handler on a field script in the main stack for example. Must i pass that message...?

Code: Select all

on exitField
// doo stuff
pass exitField
end exitField
If i dont pass this message. would this issue be expected.?
Kind Regards
Gary

https://www.doobox.co.uk

doobox
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 284
Joined: Tue May 24, 2011 11:47 pm

Re: Struggling Handling Focus of 1 field

Post by doobox » Wed Jul 18, 2012 9:43 am

Sussed it :-)

It was due to the fact i had a graphic covering the entire background of the stack.
So when clicking outside the field the graphic was catching the click, and expected messages were not being sent.

removed the graphic and all works as expected :-)
Kind Regards
Gary

https://www.doobox.co.uk

palanolho
Posts: 122
Joined: Sat Apr 27, 2013 11:40 pm

Re: Struggling Handling Focus of 1 field

Post by palanolho » Sun Jun 16, 2013 5:30 pm

OK, I'm having the same problem.

SO, what i need (as doobox explained) is to:

I'm fulfilling an input box, then, I click outside of that input box (anywhere, even if its another control, image or whatever) and that makes the input box lose the focus.

As doobox told, if I click on TAB key or click on an empty space on my card (with no component or image below) it works, however, I have lots of images and controls on my card and it will be difficult not to click on one.

What I'm trying to do is to pass the value of the input box to another input box when I click outside of it.

Anyone has any idea how I can do this??

Many thanks

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10305
Joined: Wed May 06, 2009 2:28 pm

Re: Struggling Handling Focus of 1 field

Post by dunbarx » Sun Jun 16, 2013 6:03 pm

If I understand, you want to put the contents of a field into another field whenever you click outside that field? Try this in the field script:

Code: Select all

on mouseLeave
   watchForClick
end mouseLeave

on watchForClick
   if the mouse is down then
      put random(99) into fld 2
      cancel item 1 of the last line of the pendingmessages
      exit to top
   end if
   send "watchForClick" to me in 1
end watchForClick
Now I did this with two fields, and just put a random number into the second field. i am sure you can modify this to accommodate your particular case. This has the advantage that is makes no difference where the mouse is when you click.

Craig Newman

palanolho
Posts: 122
Joined: Sat Apr 27, 2013 11:40 pm

Re: Struggling Handling Focus of 1 field

Post by palanolho » Sun Jun 16, 2013 6:26 pm

I tried your scrip on the field that I'm editing, but It doesn't work for me :(
I tried to click on a rectangle or on an image, and nothing :(

Also, I wound like to make this the default behaviour of my application, since its the default behaviour in most applications and websites.

Is it possible to do this?

many thanks

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10305
Joined: Wed May 06, 2009 2:28 pm

Re: Struggling Handling Focus of 1 field

Post by dunbarx » Sun Jun 16, 2013 6:40 pm

I tested in a new stack with only the two fields on it. Try that. It will work, and then we have to figure out what is stopping it from working in your stack.

Craig Newman

palanolho
Posts: 122
Joined: Sat Apr 27, 2013 11:40 pm

Re: Struggling Handling Focus of 1 field

Post by palanolho » Sun Jun 16, 2013 6:45 pm

I also tried like you said, and it works, the problem is when i click in an area not empty.

for example, when i click on an image or rectangle graphic (for example)

jacque
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 7389
Joined: Sat Apr 08, 2006 8:31 pm
Contact:

Re: Struggling Handling Focus of 1 field

Post by jacque » Sun Jun 16, 2013 7:23 pm

Maybe all the field needs is a "closefield" handler. It will get that whenever you click outside of it. In the closefield handler, move the data to the other field. Then you don't need any mouseup handlers at all.
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10305
Joined: Wed May 06, 2009 2:28 pm

Re: Struggling Handling Focus of 1 field

Post by dunbarx » Sun Jun 16, 2013 8:17 pm

Palanolhol:

I see no difference where I click. In any graphic, any object of any kind or anywhere on the card. In, fact, you can click outside the window and it will still work.

Jacque

Cleaner and simpler. You would need an "exitField" as well, if nothing was changed.

Craig

jacque
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 7389
Joined: Sat Apr 08, 2006 8:31 pm
Contact:

Re: Struggling Handling Focus of 1 field

Post by jacque » Sun Jun 16, 2013 8:24 pm

An exitField might be useful, though if nothing was changed, the second field might not need an update. I guess it depends on what the stack is doing.
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com

Post Reply