To focus on field without have the text selected

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
Mag
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 802
Joined: Fri Nov 16, 2012 10:51 pm

To focus on field without have the text selected

Post by Mag » Thu Feb 20, 2014 2:05 am

Hi all!

I'm trying to use the focus on field command in a series of fields with lockText true, unfortunately when the field get the focus the entire text of the field is selected, is there a way to avoid the text selection when move from a field to another?

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

Re: To focus on field without have the text selected

Post by dunbarx » Thu Feb 20, 2014 2:14 am

Hi.

Not sure how you are doing this, but if you focus on a field that contains text, the default behavior is to set the cursor at the end of that text, not to select all. Anyway, try this in a button somewhere:

Code: Select all

on mouseUp
   focus on fld 1
   select empty
end mouseUp
Craig

EDIT: Hmmm, this seemed reasonable, but of course selecting empty defocuses the field. Try something else...

More Hmmm. Setting the cursor to none and locking does not work. And why should it? There are always two cursors when a blinking one is in the field and the "ordinary" one is hanging around the card.

Mag
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 802
Joined: Fri Nov 16, 2012 10:51 pm

Re: To focus on field without have the text selected

Post by Mag » Thu Feb 20, 2014 2:45 am

Maybe select text something? But what? :oops:

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

Re: To focus on field without have the text selected

Post by dunbarx » Thu Feb 20, 2014 3:38 am

OK.

This has to win the silver for ugliest kluge of the Olympics. It works, and if you never do anything to the text of that field it can stay. Otherwise, ugh.

In a button script, with a field with text in it:

Code: Select all

on mouseUp
   get the scroll of fld 1
   focus on fld 1
   repeat 100
      put  return after fld 1
   end repeat
      select after text of fld 1
      set the scroll of fld 1 to it
end mouseUp
Oh. Did I mention it was awful?

Craig

LCNeil
Livecode Staff Member
Livecode Staff Member
Posts: 1223
Joined: Wed Oct 03, 2012 4:07 pm

Re: To focus on field without have the text selected

Post by LCNeil » Thu Feb 20, 2014 9:48 am

Hi Mag,

Just tried this and it seems to work (Mac OSX)

Code: Select all

on mouseUp
   focus on fld 1
   select char 0 of fld 1
end mouseUp
Kind Regards,


Neil Roger
--
RunRev Support Team ~ http://www.runrev.com
-

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

Re: To focus on field without have the text selected

Post by dunbarx » Thu Feb 20, 2014 4:21 pm

Neil.

Right. Thank heaven.

Craig

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

Re: To focus on field without have the text selected

Post by jacque » Thu Feb 20, 2014 6:13 pm

A bit of trivia: fields with autoTab set to true will auto-select the entire field content. Fields with autoTab set to false will set the insertion point at the end. Or at least it used to be that way, I haven't checked in a while.
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com

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

Re: To focus on field without have the text selected

Post by dunbarx » Thu Feb 20, 2014 7:25 pm

Jacque.

That is right. Forgot about autoTab

Mag, listen to Jacque.

Craig

Mag
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 802
Joined: Fri Nov 16, 2012 10:51 pm

Re: To focus on field without have the text selected

Post by Mag » Thu Feb 20, 2014 9:36 pm

runrevneil wrote:Hi Mag,

Just tried this and it seems to work (Mac OSX)

Code: Select all

on mouseUp
   focus on fld 1
   select char 0 of fld 1
end mouseUp
Kind Regards,


Neil Roger
--
RunRev Support Team ~ http://www.runrev.com
-

Thank you Neil works fine and it suits perfectly the needs of my current project. :D

So now I replaced

focus on field "abc"

with

select char 0 of fld "abc"


Thank you Jacque and Craig for your help!

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

Re: To focus on field without have the text selected

Post by dunbarx » Thu Feb 20, 2014 10:06 pm

Mag,

So your instinct about "select something..." was spot on.

Craig

Mag
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 802
Joined: Fri Nov 16, 2012 10:51 pm

Re: To focus on field without have the text selected

Post by Mag » Thu Feb 20, 2014 11:22 pm

dunbarx wrote:Mag,

So your instinct about "select something..." was spot on.

Craig
Hehehe
:lol:

Post Reply