Return in a text 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
GregWills
Posts: 69
Joined: Sun Aug 30, 2015 7:51 am

Return in a text field

Post by GregWills » Mon Mar 13, 2017 10:57 am

Hi All
I am wanting to allow the user enter 10 lines of text only: in a text field. After 10 words, I want the return input to activate an action, but not move the cursor to the next line. In essence I want a field that only has 10 lines.

I have tried a number of approaches. I am using "on returninfield" in the text field;

if line 10 of me is not empty then -- this only happens at line 10
...
if return is among the characters of me then select line 1 of me

When this script runs, the cursor goes to the top of the text field (this is what I want) ... but, deletes the first line. I just want to place the cursor at beginning of the first line.

I'm sure there is an easy answer!! Any suggestions please.

Thanks

Greg

jmburnod
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 2718
Joined: Sat Dec 22, 2007 5:35 pm
Location: Genève
Contact:

Re: Return in a text field

Post by jmburnod » Mon Mar 13, 2017 12:29 pm

Hi Greg,
I just want to place the cursor at beginning of the first line.
Why not

Code: Select all

   select before text of me 
Best regards
Jean-Marc
https://alternatic.ch

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

Re: Return in a text field

Post by dunbarx » Mon Mar 13, 2017 3:42 pm

Jean-Marc has cut to the chase.

But I wonder how you can query whether there is a return "among the characters of me" and make any sense of the answer. You have at least nine returns already, no?

Anyway, whatever works usually works, though you may find that such a pathway is not robust.

Craig Newman

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

Re: Return in a text field

Post by jacque » Mon Mar 13, 2017 4:42 pm

The behavior you want is built in. Make the field exactly 10 lines tall and set the autotab property to true. A carriage return in the field will automatically select the text of the next field.

This won't prevent users from pasting more than 10 lines however.
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com

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

Re: Return in a text field

Post by dunbarx » Mon Mar 13, 2017 5:35 pm

Jacque.

It is what I meant by "robust". Though I am likely misusing that term. The shortcut means he cannot change the text size, for example.

Craig

Lagi Pittas
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 365
Joined: Mon Jun 10, 2013 1:32 pm

Re: Return in a text field

Post by Lagi Pittas » Mon Mar 13, 2017 6:41 pm

Hi

I'd do it a little differently with the rawkeydown as you can then have control over when the tab key is executed to exit the field and probably more weird and wonderful shenanigans all in the same handler.

Code: Select all

on RawKeyDown pKey
   if pKey = 65293 then
      if the number of lines of me = 10 then
          select before me
          exit RawKeyDown
         end if 
   end if
   pass RawKeyDown
end RawKeyDown

Regards Lagi

GregWills
Posts: 69
Joined: Sun Aug 30, 2015 7:51 am

Re: Return in a text field

Post by GregWills » Mon Mar 13, 2017 11:12 pm

Thank you all for your replies

Jean-Marc - Thanks for your suggestion. This is one version that I tried. The result was the cursor placed on the second line. This was I think because the return was included. I then tried to backspace to remove this. I didn’t have much joy with this.

Craig - Yes, my initial try at this had an unplanned result!! ALL the returns were removed from the field!! I have (not efficiently at the moment) scripts for the ten lines so this doesn’t happen.

Jacque - Thank you. This does the trick. Damn. It was there all the time!

Lagi - Thank you for your reply. I am going to explore you approach further later on today :-)

Regards

Greg

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

Re: Return in a text field

Post by dunbarx » Tue Mar 14, 2017 12:03 am

Jacque invariably has simple and elegant solutions.

But beware, my comment about such things as the textSize will break that happy state.

Craig

Post Reply

Return to “Getting Started with LiveCode - Complete Beginners”