Control of Text Fields

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

kray
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 56
Joined: Sat Apr 08, 2006 5:28 pm
Location: Eau Claire, WI
Contact:

Re: Control of Text Fields

Post by kray » Thu Nov 11, 2021 8:52 pm

Great stack, Roger! I know I'm kind of late to the party, but just FYI you can also use the type command for entering the numbers (an oldie, but a goodie):

Code: Select all

-- Modifying your behavior script
on mouseUp
  type (the label of me)
end mouseUp
Also, for the "Del" button, I think this simple script would work:

Code: Select all

on mouseUp
  delete char (word 4 of the selectedChunk) of the focusedObject
end mouseUp
(and if you ever needed a "forward delete", you could just change it to "word 2 of the selectedChunk")

Just my 2 cents,


Ken
Ken Ray
Sons of Thunder Software
Email: kray@sonsothunder.com
Web site: http://www.sonsothunder.com

RogGuay
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 114
Joined: Fri Apr 28, 2006 12:10 am
Location: Seattle

Re: Control of Text Fields

Post by RogGuay » Sat Nov 13, 2021 12:32 am

Thank you for these tips, Ken. Is there am advantage to using the type command over put?

Roger

richmond62
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 9388
Joined: Fri Feb 19, 2010 10:17 am
Location: Bulgaria

Re: Control of Text Fields

Post by richmond62 » Sat Nov 13, 2021 8:57 am

Oddly enouugh, TYPE does not seem to be in the dictionary.

For the sake of argument this script locks up Livecode:

Code: Select all

on mouseUp
   put fld "f3" into GUFF
   put GUFF into fld "f1"
   type GUFF into fld "f2"
end mouseUp
Last edited by richmond62 on Sat Nov 13, 2021 9:51 am, edited 1 time in total.

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

Re: Control of Text Fields

Post by Klaus » Sat Nov 13, 2021 9:45 am

richmond62 wrote:
Sat Nov 13, 2021 8:57 am
Oddly enouugh, TYPE does not seem to be in the dictionary...
Is that so?
Attachments
Bildschirmfoto 2021-11-13 um 09.44.07.jpg

richmond62
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 9388
Joined: Fri Feb 19, 2010 10:17 am
Location: Bulgaria

Re: Control of Text Fields

Post by richmond62 » Sat Nov 13, 2021 9:50 am

SShot 2021-11-13 at 10.48.55.png
-
NO, it is NOT so . . .

Allow me to blame that on the fact I have only had my first cup of coffee this morning. :?

The spelling of "enouugh" should be a dead give away.

AND, why, forbye, does this:

Code: Select all

on mouseUp
   put fld "f3" into GUFF
   put GUFF into fld "f1"
   type GUFF into fld "f2"
end mouseUp
NOT result in the TEXT in GUFF being typed into fld "f2"?

I'm aye forfochen. :(

Disnae seem to like this either:
-
SShot 2021-11-13 at 10.56.13.png

bn
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 4003
Joined: Sun Jan 07, 2007 9:12 pm
Location: Bochum, Germany

Re: Control of Text Fields

Post by bn » Sat Nov 13, 2021 10:10 am

From the dictionary:
The type command does not automatically place an insertion point in a
field, so if you want to simulate typing into a field, you must first
use the select command to place the insertion point:

select after field "Data"
type "Hello"
Try this.

Kind regards
Bernd

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

Re: Control of Text Fields

Post by Klaus » Sat Nov 13, 2021 10:14 am

OK, then you need to read the whole thingie! :D
This is how to do it, as mentioned in the dictionary:

Code: Select all

on mouseUp
   put fld "f3" into GUFF
   put GUFF into fld "f1"
   
   ## We cannot TYPE diretly INTO, thus:
   focus on fld "f2"
   ## or to specify an insertion point if there is already text in the target field:
   ## select AFTER fld "f2"
   
   ## NOW:
   type GUFF
end mouseUp

richmond62
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 9388
Joined: Fri Feb 19, 2010 10:17 am
Location: Bulgaria

Re: Control of Text Fields

Post by richmond62 » Sat Nov 13, 2021 5:46 pm

I did mention the lack of a second cup of coffee.
-
SShot 2021-11-13 at 18.46.16.png
SShot 2021-11-13 at 18.46.16.png (16.37 KiB) Viewed 4569 times
-
?
-
SShot 2021-11-13 at 18.48.07.png
SShot 2021-11-13 at 18.48.07.png (16.47 KiB) Viewed 4569 times
-
At which point LiveCode froze.
-
SShot 2021-11-13 at 18.51.01.png
SShot 2021-11-13 at 18.51.01.png (17.64 KiB) Viewed 4566 times
-
Aah.

richmond62
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 9388
Joined: Fri Feb 19, 2010 10:17 am
Location: Bulgaria

Re: Control of Text Fields

Post by richmond62 » Sat Nov 13, 2021 5:53 pm

SShot 2021-11-13 at 18.52.32.png
SShot 2021-11-13 at 18.52.32.png (17.69 KiB) Viewed 4564 times
-

Code: Select all

on mouseUp
   put fld "f3" into GUFF
   put GUFF into fld "f1"
   focus on fld "f2"
   type GUFF into fld "f2"
end mouseUp
No.

richmond62
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 9388
Joined: Fri Feb 19, 2010 10:17 am
Location: Bulgaria

Re: Control of Text Fields

Post by richmond62 » Sat Nov 13, 2021 5:59 pm

SShot 2021-11-13 at 18.54.32.png
-
Is this because:

1. My text in my original variable is far too large?

2. LC does not like to TYPE from a variable?

-
SShot 2021-11-13 at 18.57.00.png
-
Apparently #1
-
BUT . . . 'No' . . . after that the thing mysteriously works.

The "advantage" of TYPE s that the text takes up to 10 times as long to end up in the target field, BUT you
can have the pleasure of watching it appear letter-by-letter.

BUT "threw a bluey at the end":
-
SShot 2021-11-13 at 19.02.33.png

richmond62
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 9388
Joined: Fri Feb 19, 2010 10:17 am
Location: Bulgaria

Re: Control of Text Fields

Post by richmond62 » Sat Nov 13, 2021 6:04 pm

Somewhat underwhelmed by TYPE.
Attachments
PUT or TYPE.livecode.zip
Here's the stack.
(2.32 KiB) Downloaded 70 times

jacque
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 7238
Joined: Sat Apr 08, 2006 8:31 pm
Location: Minneapolis MN
Contact:

Re: Control of Text Fields

Post by jacque » Sat Nov 13, 2021 6:40 pm

RogGuay wrote:
Sat Nov 13, 2021 12:32 am
Thank you for these tips, Ken. Is there am advantage to using the type command over put?
The put command involves no messages, the text goes directly into the field. The type command simulates user interaction and sends all the normal messages - keyDown, keyUp, etc. So if you have handlers that monitor user typing, they will trigger normally when the type command executes.
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com

jacque
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 7238
Joined: Sat Apr 08, 2006 8:31 pm
Location: Minneapolis MN
Contact:

Re: Control of Text Fields

Post by jacque » Sat Nov 13, 2021 6:45 pm

The "advantage" of TYPE s that the text takes up to 10 times as long to end up in the target field
Set the typingRate to 0. The default is 100ms.
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com

richmond62
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 9388
Joined: Fri Feb 19, 2010 10:17 am
Location: Bulgaria

Re: Control of Text Fields

Post by richmond62 » Sat Nov 13, 2021 7:59 pm

Ouch, trust Jacque to "pip me at the post": what can I say, except,

Lots of love, Richmond. 8)

Between Jacque and Klaus I am doubly humbled.

alextweedly
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 4
Joined: Sat Apr 08, 2006 9:52 am
Location: Edinburgh
Contact:

Re: Control of Text Fields

Post by alextweedly » Sun Nov 14, 2021 12:10 am

Ken,
you suggested a simpler version for the Del button, namely

[code]
on mouseUp
delete char (word 4 of the selectedChunk) of the focusedObject
end mouseUp
[/code]
but this doesn't work correctly in the case of an active text selection; the desired (correct) effect in that case is to delete the selected text, while this simple suggestion removes only the last character.

A simple fix is to do
[code]
on mouseup
type " " -- remove existing selection if there is one, then add a space
delete char (word 4 of the selectedChunk) of the focusedObject -- remove that space
end mouseUp
[/code]

Sorry - can't figure out how to get code inserted properly !?

Post Reply

Return to “Getting Started with LiveCode - Complete Beginners”