Accepting only Upper Case characters in input field
583687Dec 15 2009 — edited Dec 16 2009Hello,
I want to accept only upper case characters in input field component. When user types any character, it should automatically convert it to upper case.
After doing some research(Checking forum, Google), i found following ways,
Using converters, but this will work when user do a focus lost after entering the value.
Adding a style class, but the actual value submitted can be in any case.
I want something like while typing only, character should get converted to upper case. There is one more way, but this way works only in IE, it doesnt work in Firefox.
1. Add one ClientListener of type keyPress on the component (tfdComponent),
ClientListenerSet l_clientListeners = tfdComponent.getClientListeners();
l_clientListeners.addListener("keyPress", "convertToUpperCase");
tfdComponent.setClientListeners( l_clientListeners);
2. Now in the java script function, just conver the current input key code to upper case and set it back. This can be done as,
function convertToUpperCase( _event ) {
var currText = null;
currText = String.fromCharCode(window.event.keyCode);
window.event.keyCode = currText.toUpperCase().charCodeAt(0);
}
But above approach only works in IE as window.event object is provided by IE.
I need a good way to achieve this functionality in any browser.
- Sujay