Limit character number in field
Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller
Limit character number in field
Hi.
I've looked through the dictionary and online but can't find anything that shows how to limit the number of characters in a text feld. Could someone possibly help?
Many thanks
Bidge
I've looked through the dictionary and online but can't find anything that shows how to limit the number of characters in a text feld. Could someone possibly help?
Many thanks
Bidge
-
- Posts: 33
- Joined: Tue Apr 25, 2017 8:13 pm
Re: Limit character number in field
Hi there everyone!
Related to this topic: how do I limit the field to entries of real numbers from 0-100 (for example 25; 50; 74.5)?
Thank you for your help.
Vasco
Related to this topic: how do I limit the field to entries of real numbers from 0-100 (for example 25; 50; 74.5)?
Thank you for your help.
Vasco
-
- VIP Livecode Opensource Backer
- Posts: 9670
- Joined: Wed May 06, 2009 2:28 pm
- Location: New York, NY
Re: Limit character number in field
Hi.
What you need to do is to draw back a bit from a simple keyboard entry, and validate the input as a whole. Might the "ask" command be useful here? Write back if you run into trouble.
Craig Newman
What you need to do is to draw back a bit from a simple keyboard entry, and validate the input as a whole. Might the "ask" command be useful here? Write back if you run into trouble.
Craig Newman
-
- Posts: 33
- Joined: Tue Apr 25, 2017 8:13 pm
Re: Limit character number in field
Hi Craig,dunbarx wrote:Hi.
What you need to do is to draw back a bit from a simple keyboard entry, and validate the input as a whole. Might the "ask" command be useful here? Write back if you run into trouble.
Craig Newman
The ask command opens a dialog right? In this case I think it would be better to set "if" conditions. I have a large number of fields that the user have to complete with percentages. I wanted to block the input...
I've something like this now:
on keyDown pKey
if pKey is a number or pKey is "." then
pass keyDown
else
beep
end if
end keyDown
I wanted the number to be less than 100, but cant figure out how to do it.
Thank you!
Re: Limit character number in field
For some reason I received an email that someone replied to one of my extremely old threads
Many thanks
Cheers
Bidge
Many thanks
Cheers
Bidge
-
- VIP Livecode Opensource Backer
- Posts: 9670
- Joined: Wed May 06, 2009 2:28 pm
- Location: New York, NY
Re: Limit character number in field
Hmmm.
Not sure I understand your setup. But say you have a lot of fields. Are they locked? If so they will respond to "mouseUp" messages. If not, we will explore other ways. But if so, in the card script, you might have something like:
This should be very readable. The "target", if you are not familiar, should be carefully studied and practiced. Now if the field is not locked, write back. Or rather lock them; you will likely want to.
Craig
Not sure I understand your setup. But say you have a lot of fields. Are they locked? If so they will respond to "mouseUp" messages. If not, we will explore other ways. But if so, in the card script, you might have something like:
Code: Select all
on mouseUp
ask "Enter a number"
if it is a number and it >= 0 and it <= 100 then put it into the target
end mouseUp
Craig
-
- VIP Livecode Opensource Backer
- Posts: 7239
- Joined: Sat Apr 08, 2006 8:31 pm
- Location: Minneapolis MN
- Contact:
Re: Limit character number in field
Just add the third condition to the test:if pKey is a number or pKey is "." then
Code: Select all
if (pKey is a number or pKey is ".") and pKey <= 100 then
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com
HyperActive Software | http://www.hyperactivesw.com
-
- Posts: 33
- Joined: Tue Apr 25, 2017 8:13 pm
Re: Limit character number in field
I am actually using it to make questions related to the topic! =Dbidgeeman wrote:For some reason I received an email that someone replied to one of my extremely old threads
Many thanks
Cheers
Bidge
I'm the one who should say thank you.
Craig,dunbarx wrote:Hmmm.
Not sure I understand your setup. But say you have a lot of fields. Are they locked? If so they will respond to "mouseUp" messages. If not, we will explore other ways. But if so, in the card script, you might have something like:This should be very readable. The "target", if you are not familiar, should be carefully studied and practiced. Now if the field is not locked, write back. Or rather lock them; you will likely want to.Code: Select all
on mouseUp ask "Enter a number" if it is a number and it >= 0 and it <= 100 then put it into the target end mouseUp
Craig
Thank you so much for this, it's a great way around this problem, but I may have too many fields for this to be practical.
I have 36 fields, and not all of them have the same limits, so I may have to code them individually. All of them are unlocked and I wished that if the user didn't entered a number within the limits stablished in the code then the field remained empty. In so many fields I think it would be boring or annoying to the user answering to 36 dialogs (but I will use your idea to some of the fields - the dialog can add some relevant information for the user).
Thank you!
-
- Posts: 33
- Joined: Tue Apr 25, 2017 8:13 pm
Re: Limit character number in field
Hi jacque!jacque wrote:Just add the third condition to the test:if pKey is a number or pKey is "." then
Code: Select all
if (pKey is a number or pKey is ".") and pKey <= 100 then
I've tried that but no success... I can't get it to work. The behaviour is just as if I didn't add that to the code.
Thank you anyway!
-
- VIP Livecode Opensource Backer
- Posts: 7239
- Joined: Sat Apr 08, 2006 8:31 pm
- Location: Minneapolis MN
- Contact:
Re: Limit character number in field
Did you include the parentheses?
You can use a single handler in the card script if you store each field limit as a custom property in the field and have the "if" statement check the property instead of a hard coded number.
I agree that using a dialog in this situation isn't appropriate. All modern OSs discourage use of dialogs now anyway. You are on the right track.
You can use a single handler in the card script if you store each field limit as a custom property in the field and have the "if" statement check the property instead of a hard coded number.
I agree that using a dialog in this situation isn't appropriate. All modern OSs discourage use of dialogs now anyway. You are on the right track.
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com
HyperActive Software | http://www.hyperactivesw.com
-
- Posts: 33
- Joined: Tue Apr 25, 2017 8:13 pm
Re: Limit character number in field
I did included the parentheses... And I've tried in different releases of LiveCode to test if it was some bug...jacque wrote:Did you include the parentheses?
You can use a single handler in the card script if you store each field limit as a custom property in the field and have the "if" statement check the property instead of a hard coded number.
I agree that using a dialog in this situation isn't appropriate. All modern OSs discourage use of dialogs now anyway. You are on the right track.
Thank you!
-
- VIP Livecode Opensource Backer
- Posts: 7239
- Joined: Sat Apr 08, 2006 8:31 pm
- Location: Minneapolis MN
- Contact:
Re: Limit character number in field
Now that I am at the computer and not answering off the top of my head, I see what is failing. Try this:
Code: Select all
on keydown pKey
if (pKey is a number or pKey is ".") then
if (me & pKey) <= 100 then
pass keydown
end if
end if
end keydown
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com
HyperActive Software | http://www.hyperactivesw.com
-
- Posts: 33
- Joined: Tue Apr 25, 2017 8:13 pm
Re: Limit character number in field
Thank you so so much, with this I can continue to improve my work!jacque wrote:Now that I am at the computer and not answering off the top of my head, I see what is failing. Try this:Code: Select all
on keydown pKey if (pKey is a number or pKey is ".") then if (me & pKey) <= 100 then pass keydown end if end if end keydown
I don't understand why it only worked with this method. Out of curiosity, why our last ideia:
Code: Select all
if (pKey is a number or pKey is ".") and pKey <= 100 then
didn't work?
Thanks to all!