PDA

View Full Version : TextField - force lower case entries to upper case?



Bucs
15 Jun 2010, 3:37 PM
Trying to find the best way to force lower case keys to upper case immediately upon entry in certain fields an can't really see an easy solution to this. I know I can use a mask and regex to limit keys, but that is not very intuitive to the user as the keys simply won't work (app will have VERY un-savvy web users). I would rather convert it for them automatically. I know I can add a listener for the keypress which will give me the key that was pressed, but besides the ASCII value, what else is there to do? Was hoping for a toUpper() function but not there.

The "hack" is to just wait until they exit the field and convert to upper, which I guess will work if that is my only option. Any other way to do this on keyress?

Thanks :)

Animal
15 Jun 2010, 9:22 PM
Use CSS to change its appearance to uppercase, and then inject a DOM change listener in to perform the actual conversion of the field value.

https://developer.mozilla.org/En/Core_JavaScript_1.5_Reference/Objects/String/FromCharCode

https://developer.mozilla.org/en/Core_JavaScript_1.5_Reference/Global_Objects/String/toUpperCase

Bucs
17 Jun 2010, 5:38 AM
Thanks Animal, but how are you suggesting I change the "appearance" of the letter just typed via CSS?

Animal
17 Jun 2010, 5:41 AM
http://www.w3.org/TR/CSS2/text.html#propdef-text-transform

Bookmark this: http://www.w3.org/TR/CSS2/cover.html#minitoc and refer to it often.

Bucs
17 Jun 2010, 5:46 AM
Wow, did not know that text-transform value...thanks!

cherbert
30 Jun 2010, 2:42 AM
Just a word of warning on this subject..

The CSS transform is only a visual thing. When you submit / post these values to a database the text will be as the user typed it.

Bucs
30 Jun 2010, 2:44 AM
Yes, I handled that as Animal suggested. thx

Animal
30 Jun 2010, 3:07 AM
Just a word of warning on this subject..

The CSS transform is only a visual thing. When you submit / post these values to a database the text will be as the user typed it.

http://www.sencha.com/forum/showthread.php?101715-TextField-force-lower-case-entries-to-upper-case&p=477394#post477394