Limit a text field to a single line?
Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller
Limit a text field to a single line?
Is there a way to limit a text field to a single line so that the user could not use the return key to make a second line? I've tried to find info on this topic but have not been successful. One would think it would be a property of the field like in Visual Basic where there are single line text fields and "note" text fields, meaning they would allow for as many lines as the user wanted. Any help would be appreciated.
urbaud
Re: Limit a text field to a single line?
Hi urbaud,
I might be reading this wrong, but couldn't you trap the
on returnInField
&
on enterInFiled messages and not let them pass?
I'm sure there must be an easier way though.
Simon
I might be reading this wrong, but couldn't you trap the
on returnInField
&
on enterInFiled messages and not let them pass?
I'm sure there must be an easier way though.
Simon
I used to be a newbie but then I learned how to spell teh correctly and now I'm a noob!
Re: Limit a text field to a single line?
I could not resist.
What Simon says.
In your field script:
on returnInField
end returnInField
There is no native one-liner, as you mentioned. Better to roll your own. A label field sort of does what you wished for, but not really.
Craig Newman
Sorry, Simon
What Simon says.
In your field script:
on returnInField
end returnInField
There is no native one-liner, as you mentioned. Better to roll your own. A label field sort of does what you wished for, but not really.
Craig Newman
Sorry, Simon
Re: Limit a text field to a single line?
What Craig says...
but isn't the Enter key on a keyboard also used? err... wait ... looking down I see mine is labeled Enter, so maybe I mean Return.
I think I read somewhere that Win machines have it all wrong and that Enter is used for numeric keypads and Return should be the normal linefeed.
At any rate I think
on enterInField
end enterInField
Should be used as well.
Simon
EDIT: From the LC dictionary
but isn't the Enter key on a keyboard also used? err... wait ... looking down I see mine is labeled Enter, so maybe I mean Return.
I think I read somewhere that Win machines have it all wrong and that Enter is used for numeric keypads and Return should be the normal linefeed.
At any rate I think
on enterInField
end enterInField
Should be used as well.
Simon
EDIT: From the LC dictionary
Comments:
The Enter key is usually located on the numeric keypad. It is a different key from the Return key (confusingly labeled "Enter" on some keyboards), which is usually located above the right-hand Shift key.
I used to be a newbie but then I learned how to spell teh correctly and now I'm a noob!
Re: Limit a text field to a single line?
As usual there are always little things kicking around.
You have your returnInField handler, right?
Make sure you set the "dontWrap" of the field, or you might see what appears to be multiple lines, even though there is only one. In fact, if you play around a little with a field with a lot of text and with its "dontWrap" set to "false", you can place the cursor lower down just as if you allowed multiple lines. It is the difference between physical and logical lines.
So you may want to think about limiting the amount of text allowed in a single line, so it physically just fits, unless the excess that runs over the edge is not a concern. Can you do that? Write back if not.
EDIT:
Simon, I don't think sending an "enter" to an editable field will do much, especially move the selection down a line.
Craig Newman
You have your returnInField handler, right?
Make sure you set the "dontWrap" of the field, or you might see what appears to be multiple lines, even though there is only one. In fact, if you play around a little with a field with a lot of text and with its "dontWrap" set to "false", you can place the cursor lower down just as if you allowed multiple lines. It is the difference between physical and logical lines.
So you may want to think about limiting the amount of text allowed in a single line, so it physically just fits, unless the excess that runs over the edge is not a concern. Can you do that? Write back if not.
EDIT:
Simon, I don't think sending an "enter" to an editable field will do much, especially move the selection down a line.
Craig Newman
Re: Limit a text field to a single line?
You can trap the messages as noted above, or you can set the autoTab property of the field to true
Re: Limit a text field to a single line?
You can use textChanged message and check if there is cr, lf or crlf, and then replace with space or empty if yes.
Marek
Marek
Re: Limit a text field to a single line?
Any editable field with it's autotab set to true will tab to the next field when the text reaches the last line and the user hits the return key. If you size the field so it is only one line high then you have a limited one line field. No script required.
Oops, I see shaosean beat me to it.
Oops, I see shaosean beat me to it.
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com
HyperActive Software | http://www.hyperactivesw.com
Re: Limit a text field to a single line?
You are right Jacque and Shaosean, but without script enter moves you out of the field.
So when somebody hits "enter" accidentally, he must come back to the field in place when he finished. Using the script the "enter" is omitted or replaced by any other character (space, tab, dot, ... or empty=nothing).
It depends from what you need and there are two different solutions.
Marek.
So when somebody hits "enter" accidentally, he must come back to the field in place when he finished. Using the script the "enter" is omitted or replaced by any other character (space, tab, dot, ... or empty=nothing).
It depends from what you need and there are two different solutions.
Marek.
Re: Limit a text field to a single line?
First of all I want to thank all of you who made suggestions regarding this post. Secondly, I'm now really confused. I'm not sure what to do and which suggestion to use. Maybe if I'm more specific that will help you to know what I'm trying to do. Picture this: one large text field (t1) and one small text field (t2) and a button labeled "Find". The handler in the Find btn is:
Rather than use the mouse to click on the Find btn for each instance of “found text” I’d like to use the Enter or Return key. My preference is the Enter key. I enter the characters I want to find into fld “t2” and click the mouse on the Find button. It finds the first instance of the text to be found. Assuming there is more than one instance of the text to be found I’d like to press the Enter key each time. But, if I press Enter it moves the cursor in fld “t2” to the next line. If I use the AutoTab as suggested that doesn’t really help either. Some of you suggested that I use an “enterInField” handler in fld “t2”. Problem is, I don’t know what the code should be in the handler and will it stop the cursor from going to the next line? As you might have guessed I’m somewhat new to LC. So, any suggestions, etc. would be much appreciated.
Code: Select all
select before text of fld "t1"
put fld "t2" into searchText
find chars searchText in fld "t1"
urbaud
Re: Limit a text field to a single line?
just wrap your script in:
on returnInField
--Your script
end returnInField
on enterInField
returnInField
end enterInField
Make sure this script is in the field script
Simon
on returnInField
--Your script
end returnInField
on enterInField
returnInField
end enterInField
Make sure this script is in the field script
Simon
I used to be a newbie but then I learned how to spell teh correctly and now I'm a noob!
Re: Limit a text field to a single line?
Simon,
Thank you for your reply. I appreciate your comments and the suggested code. Thanks again.
Thank you for your reply. I appreciate your comments and the suggested code. Thanks again.
urbaud
Re: Limit a text field to a single line?
Hi urbaud,
What you are trying to do with the word search is very possible in LC. I think you should check the dictionary for these terms that may help you:
wordOffset (note the part on words to skip)
wholeMatches
textChanged
Have fun!
Simon
What you are trying to do with the word search is very possible in LC. I think you should check the dictionary for these terms that may help you:
wordOffset (note the part on words to skip)
wholeMatches
textChanged
Have fun!
Simon
I used to be a newbie but then I learned how to spell teh correctly and now I'm a noob!