Forcing all capitals in a text field

Got a LiveCode personal license? Are you a beginner, hobbyist or educator that's new to LiveCode? This forum is the place to go for help getting started. Welcome!

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller

Post Reply
ICCS_User
Posts: 12
Joined: Fri Dec 28, 2012 9:06 pm

Forcing all capitals in a text field

Post by ICCS_User » Sun Dec 30, 2012 1:14 am

Can I I force all text in a field to be in all capitals?
Thanks!

iccs

sturgis
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 1685
Joined: Sat Feb 28, 2009 11:49 pm

Re: Forcing all capitals in a text field

Post by sturgis » Sun Dec 30, 2012 1:40 am

one way would be to use the toUpper function. (in the dictionary) you can either wait for all input to complete and then change everything to upper, do using key events (keydown, or rawkeydown) or you could have it run every time the text changes in the field in any way. (including delete, returns, backspaces) using on textChanged. Or you could do it on closefield

if you use keyDown here is a simple example (placed in the field script) that might do what you wish.

Code: Select all

on keyDown pKey
-- make sure its a letter
   if pKey is among the chars of "abcdefghijklmnopqrstuvwxyz" then
      put toUpper(pKey) into pKey -- force the key to upper.
      put pKey into the selection -- put it at the current insertion point
   else
      pass keydown -- otherwise just pass the key along as is. 
   end if
end keyDown

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

Re: Forcing all capitals in a text field

Post by dunbarx » Sun Dec 30, 2012 2:41 am

Sturgis.

Small point, and one I had to test myself, but only lower case letters are affected by this function.

The dictionary even says as much, which I read only after testing. Typical.

Craig

sturgis
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 1685
Joined: Sat Feb 28, 2009 11:49 pm

Re: Forcing all capitals in a text field

Post by sturgis » Sun Dec 30, 2012 4:31 am

Only reason its in an if statement is so that it doesn't needlessly run on anything but letters. Probably no discernable speed difference, but I figured 1 if check is (even if unnoticeably) faster than a function call and an insert into a field.

Is kinda pointless do do so trying to save unmeasurable time.

Simon
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 3901
Joined: Sat Mar 24, 2007 2:54 am

Re: Forcing all capitals in a text field

Post by Simon » Sun Dec 30, 2012 7:36 am

toUpper??
That has to be the worst LC command...wait no... good command, lousy notation.
charToUpper
caseToUpper
shiftCase
charShift
I could keep going with these :D
If there are LC beginners reading this, this is the only example I know of.

Simon
I used to be a newbie but then I learned how to spell teh correctly and now I'm a noob!

ICCS_User
Posts: 12
Joined: Fri Dec 28, 2012 9:06 pm

Re: Forcing all capitals in a text field

Post by ICCS_User » Sun Dec 30, 2012 3:16 pm

sturgis wrote:one way would be to use the toUpper function. (in the dictionary) you can either wait for all input to complete and then change everything to upper, do using key events (keydown, or rawkeydown) or you could have it run every time the text changes in the field in any way. (including delete, returns, backspaces) using on textChanged. Or you could do it on closefield

if you use keyDown here is a simple example (placed in the field script) that might do what you wish.

Code: Select all

on keyDown pKey
-- make sure its a letter
   if pKey is among the chars of "abcdefghijklmnopqrstuvwxyz" then
      put toUpper(pKey) into pKey -- force the key to upper.
      put pKey into the selection -- put it at the current insertion point
   else
      pass keydown -- otherwise just pass the key along as is. 
   end if
end keyDown
This works great! However, I have another silly question. I already have an existing keyDown script (on keyDown var) in this field. How do I deal with more than one on mouseDown scripts in one field?

sturgis
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 1685
Joined: Sat Feb 28, 2009 11:49 pm

Re: Forcing all capitals in a text field

Post by sturgis » Sun Dec 30, 2012 3:53 pm

Depending on what is in the keydown, you can probably combine the two. Want to post your script?

Also, as dunbar (craig) pointed out, my script could be turned into a 1 liner since its silly to use a conditional in this CASE. (pun intended)

Post your current script, and most likely toUpper can be incorporated. (if not there are other ways to get it done.)

jacque
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 7391
Joined: Sat Apr 08, 2006 8:31 pm
Contact:

Re: Forcing all capitals in a text field

Post by jacque » Mon Dec 31, 2012 2:31 am

Simon wrote:toUpper??
That has to be the worst LC command...wait no... good command, lousy notation.
On the other hand, that's the name of the same function in lots of languages, so many people will already know it. Besides SuperCard, it's in Java, Real Basic, C++, VB, and more. Same goes for toLower.
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com

ICCS_User
Posts: 12
Joined: Fri Dec 28, 2012 9:06 pm

Re: Forcing all capitals in a text field

Post by ICCS_User » Mon Dec 31, 2012 4:32 pm

sturgis wrote:Depending on what is in the keydown, you can probably combine the two. Want to post your script?

Also, as dunbar (craig) pointed out, my script could be turned into a 1 liner since its silly to use a conditional in this CASE. (pun intended)

Post your current script, and most likely toUpper can be incorporated. (if not there are other ways to get it done.)
Here's my existing script:

local tData

on mouseenter
put fld "theData" into tData
end mouseenter

on keydown var
put var after me
if me is among the words of tData then
get lineOffset(me,tData)
put word 2 of line it of tData into fld "output"
end if
end keydown

sturgis
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 1685
Joined: Sat Feb 28, 2009 11:49 pm

Re: Forcing all capitals in a text field

Post by sturgis » Mon Dec 31, 2012 5:43 pm

ICCS_User wrote:Depending on what is in the keydown, you can probably combine the two. Want to post your script?

Also, as dunbar (craig) pointed out, my script could be turned into a 1 liner since its silly to use a conditional in this CASE. (pun intended)

Post your current script, and most likely toUpper can be incorporated. (if not there are other ways to get it done.)
Change your keydown as follows:

Code: Select all

local tData

on mouseenter
   put fld "theData" into tData
end mouseenter

on keydown var
   put toUpper(var) after me -- change this line to force the upper case.  
   if me is  among the words of tData then
      get lineOffset(me,tData)
      put word 2 of line it of tData into fld "output"
   end if
end keydown

Post Reply