Limit the label field

Anything beyond the basics in using the LiveCode language. Share your handlers, functions and magic here.

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

Post Reply
alemrantareq
Posts: 203
Joined: Wed Jul 23, 2008 8:46 am

Limit the label field

Post by alemrantareq » Thu Jun 17, 2010 1:40 pm

Hi everybody, I want to know two things -

1. How to limit the char entry in the label field? (i.e. Max five chars can be input in the label field)
2. Only numbers and letters will be allowed in the label field.

I think the aboves are very easy to scripting. I just forgot them & can't remember........pls help me :lol:

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10354
Joined: Wed May 06, 2009 2:28 pm

Re: Limit the label field

Post by dunbarx » Thu Jun 17, 2010 3:44 pm

Label fields usually have their text locked, among other things. They are used for displaying text that does not change, and one rarely types into them. I think you are asking about text fields. Try this in the field script:

Code: Select all

on keyDown var
    if var is in ".0123456789abcdefghijklmnopqrstuvwxyz" and the length of me < 5 then put var after me
end keyDown
Note that you should test this to make sure it does what you want.

Craig Newman

alemrantareq
Posts: 203
Joined: Wed Jul 23, 2008 8:46 am

Re: Limit the label field

Post by alemrantareq » Thu Jun 17, 2010 6:09 pm

Thanks Craig Newman for reply........yes i was wrong......I asked for the text field. Your script works good but I found a little problem. If I want to input a new char in the middle of text, it goes to last. I think the standard script will be -

Code: Select all

if theKey is a number and theKey is......then pass keyDown.......something like this.

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10354
Joined: Wed May 06, 2009 2:28 pm

Re: Limit the label field

Post by dunbarx » Thu Jun 17, 2010 8:40 pm

Yep, that is why we must test, test, test.

Change the script just slightly.

Code: Select all

on keyDown var
    if var is in ".0123456789abcdefghijklmnopqrstuvwxyz" and the length of me < 5 then put var after the selection
end keyDown
Do you see the difference? Playing with these adorable features of Rev is the best way to learn.

Craig Newman

alemrantareq
Posts: 203
Joined: Wed Jul 23, 2008 8:46 am

Re: Limit the label field

Post by alemrantareq » Fri Jun 18, 2010 3:23 am

Thanks Craig Newman, yes I strongly agree with you.

Yah, your new script works perfect. I made a slight difference & it also works for me -

Code: Select all

on keyDown theKey
   if theKey is in ".0123456789abcdefghijklmnopqrstuvwxyz" and the length of me < 5 then pass keyDown
end keyDown
CHEERS !!! :D

Post Reply