Page 1 of 1

How to make a field Caps-Only

Posted: Sun Oct 14, 2012 10:35 pm
by Cool Dave
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

Re: How to make a field Caps-Only

Posted: Sun Oct 14, 2012 10:57 pm
by dunbarx
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

Re: How to make a field Caps-Only

Posted: Sun Oct 14, 2012 11:54 pm
by Cool Dave
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?

Re: How to make a field Caps-Only

Posted: Mon Oct 15, 2012 12:40 am
by Klaus
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

Re: How to make a field Caps-Only

Posted: Mon Oct 15, 2012 12:54 am
by Randy Hengst
I'd put this script in the field where the user is entering text....

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

Re: How to make a field Caps-Only

Posted: Mon Oct 15, 2012 1:54 am
by dunbarx
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

Re: How to make a field Caps-Only

Posted: Tue Oct 16, 2012 2:20 am
by Cool Dave
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

Re: How to make a field Caps-Only

Posted: Tue Oct 16, 2012 2:50 am
by dunbarx
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