Return in a text field
Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller
Return in a text field
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
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
-
- VIP Livecode Opensource Backer
- Posts: 2718
- Joined: Sat Dec 22, 2007 5:35 pm
- Location: Genève
- Contact:
Re: Return in a text field
Hi Greg,
Best regards
Jean-Marc
Why notI just want to place the cursor at beginning of the first line.
Code: Select all
select before text of me
Jean-Marc
https://alternatic.ch
-
- VIP Livecode Opensource Backer
- Posts: 9662
- Joined: Wed May 06, 2009 2:28 pm
- Location: New York, NY
Re: Return in a text field
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
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
-
- VIP Livecode Opensource Backer
- Posts: 7235
- Joined: Sat Apr 08, 2006 8:31 pm
- Location: Minneapolis MN
- Contact:
Re: Return in a text field
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.
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
HyperActive Software | http://www.hyperactivesw.com
-
- VIP Livecode Opensource Backer
- Posts: 9662
- Joined: Wed May 06, 2009 2:28 pm
- Location: New York, NY
Re: Return in a text field
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
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
-
- VIP Livecode Opensource Backer
- Posts: 365
- Joined: Mon Jun 10, 2013 1:32 pm
Re: Return in a text field
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.
Regards Lagi
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
Re: Return in a text field
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
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
-
- VIP Livecode Opensource Backer
- Posts: 9662
- Joined: Wed May 06, 2009 2:28 pm
- Location: New York, NY
Re: Return in a text field
Jacque invariably has simple and elegant solutions.
But beware, my comment about such things as the textSize will break that happy state.
Craig
But beware, my comment about such things as the textSize will break that happy state.
Craig