How to make a field Caps-Only

LiveCode is the premier environment for creating multi-platform solutions for all major operating systems - Windows, Mac OS X, Linux, the Web, Server environments and Mobile platforms. Brand new to LiveCode? Welcome!

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

Post Reply
Cool Dave
Posts: 35
Joined: Mon Jun 25, 2012 8:44 pm

How to make a field Caps-Only

Post by Cool Dave » Sun Oct 14, 2012 10:35 pm

I'd be surprised if there isn't a question like this already, but I can't find any, so here it is.

I have a bunch of fields that the user can enter text in, but I want it so that anything they enter is converted to Upper Case. Is there a fast way to do this? I really don't want to have to grab it, convert it to caps, and put it back.

Is there a better way?

Dave

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

Re: How to make a field Caps-Only

Post by dunbarx » Sun Oct 14, 2012 10:57 pm

Hi.

I don't think there is a "allCaps" textstyle, though there is kind of such a thing in the inspector, but this seems to apply only to the selectedText of a field.

So check out the "toUpper" function. This has to be managed at the typing level, trapping either "keyUp" or "rawKeyUp".

This is not as onerous as you make it sound. Can you make such a script?

Craig Newman

Cool Dave
Posts: 35
Joined: Mon Jun 25, 2012 8:44 pm

Re: How to make a field Caps-Only

Post by Cool Dave » Sun Oct 14, 2012 11:54 pm

I just don't want a performance hog. Livecode pauses for half a second just for twenty or so lines. (No 'move' or loops or anything)

I can't think of a seamless way to do it, either. I just tried using rawkeydown and subtracting 32 to get the caps version, but now what do I do? 'pass rawkeydown' acts like I hadn't changed the rawkeynumber. Oh wait, keydown gives a result like "a" instead of "97" right?

Klaus
Posts: 14177
Joined: Sat Apr 08, 2006 8:41 am
Contact:

Re: How to make a field Caps-Only

Post by Klaus » Mon Oct 15, 2012 12:40 am

Hi Dave,

just tested in a field script and works:

Code: Select all

on keydown tKey
  put toupper(tKey) into the selection
end keydown
8)

Best

Klaus

Randy Hengst
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 157
Joined: Thu Jun 29, 2006 4:16 pm

Re: How to make a field Caps-Only

Post by Randy Hengst » Mon Oct 15, 2012 12:54 am

I'd put this script in the field where the user is entering text....

on keyDown theKey
put toUpper(theKey) into selection
end keyDown

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

Re: How to make a field Caps-Only

Post by dunbarx » Mon Oct 15, 2012 1:54 am

keyDown, not "keyUp", of course, or all kinds of bad things happen if you do not:

on keyDown
end keyDown

And why go through all that?

There are all kinds of needs for live field text validation, numbers only, certain chars only, caps only (yours), whatever. This is common practice, and should be embraced.

But what was causing the delays you mentioned?

Craig Newman

Cool Dave
Posts: 35
Joined: Mon Jun 25, 2012 8:44 pm

Re: How to make a field Caps-Only

Post by Cool Dave » Tue Oct 16, 2012 2:20 am

Thanks for the answer.

Yes, the code you all provided works perfectly for my needs.

Sorry for the confusion, I had to leave before I could test keyDown. I had been experimenting with rawKeyDown. I expected a bit of delay, even though it's pretty simple. But

on keydown tKey
put toupper(tKey) into the selection
end keydown

is too simple for delays.

I've been experiencing some nasty delays in just a dozen or so lines of script. I suppose a few things might be a bit of an performance killer. Is setting a loc and then setting it back to the original slower than invisible-izing it and then making it visble again?

Dave

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

Re: How to make a field Caps-Only

Post by dunbarx » Tue Oct 16, 2012 2:50 am

Glad you are comfortable with managing text entry on the fly. This is a very useful method.

The simple tasks you mentioned could not cause a noticeable delay, unless you are doing it to lots and lots of objects. Can you give an example? LC is really pretty quick, even with moving things around the screen.

Craig Newman

Post Reply