Stop user pressing Enter in entry 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

Post Reply
agraham147
Posts: 50
Joined: Thu Apr 19, 2018 6:18 am

Stop user pressing Enter in entry field

Post by agraham147 » Tue Jun 19, 2018 12:42 am

Hi there

I would like to know how to stop the user of my program from pressing the Enter or Return Key for a new line in text entry fields as I only want them to be able to provide 1 line of text. How do I do this please?

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 9648
Joined: Wed May 06, 2009 2:28 pm
Location: New York, NY

Re: Stop user pressing Enter in entry field

Post by dunbarx » Tue Jun 19, 2018 2:45 am

Hi.

Try this in the field script:

Code: Select all

on returnInfield
end returnInfield

on enterInField
end enterInField
LC will never see messages like "returnInField" that it uses to er, return in a field.

Craig Newman

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

Re: Stop user pressing Enter in entry field

Post by jacque » Tue Jun 19, 2018 5:57 pm

Alternately, size the height of the field to hold only one line and set the autotab of the field to true in the property inspector.
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com

agraham147
Posts: 50
Joined: Thu Apr 19, 2018 6:18 am

Re: Stop user pressing Enter in entry field

Post by agraham147 » Fri Jun 22, 2018 9:02 pm

Thanks guys :D

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

Re: Stop user pressing Enter in entry field

Post by richmond62 » Sat Jun 23, 2018 8:19 am

If that solution is not exciting enough for you, you can try this:

Code: Select all

on rawKeyDown RK
    switch RK
       case 65293
         --do nix
       break
       case 65421
         --do nix
       break
       default
       pass rawKeyDown
     end switch
end rawKeyDown
-
kb.png
-
case 65293 traps the RETURN key (marked in powder blue).

case 65421
traps the ENTER key (marked in pale green).

The reason for this is that to trap BOTH in the way previously suggested you would
have to use

returnInField and

enterInField
.

As the initial question was about stopping people pressing the ENTER key and NOT the RETURN key . . .

Being pedantic is such sweet joy. 8)

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 9648
Joined: Wed May 06, 2009 2:28 pm
Location: New York, NY

Re: Stop user pressing Enter in entry field

Post by dunbarx » Sat Jun 23, 2018 1:52 pm

Richmond.

I was accused, but never convicted of pedantism.

Howeveer, the OP originally did indeed ask to stop both "enter" and "return". 8)

Craig

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

Re: Stop user pressing Enter in entry field

Post by richmond62 » Sat Jun 23, 2018 3:45 pm

the Enter or Return Key
I am both accused and convicted. :D

HOWEVER: returnInField will ONLY trap the RETURN key.

https://youtu.be/HDMV4UF_-Rs

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 9648
Joined: Wed May 06, 2009 2:28 pm
Location: New York, NY

Re: Stop user pressing Enter in entry field

Post by dunbarx » Sat Jun 23, 2018 4:54 pm

HOWEVER: returnInField will ONLY trap the RETURN key.
Right. As it should. 8)

Craig

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

Re: Stop user pressing Enter in entry field

Post by jacque » Sat Jun 23, 2018 5:36 pm

Whenever possible I let the engine do it. This functionality is built in and requires no code.
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com

Post Reply

Return to “Getting Started with LiveCode - Complete Beginners”