Sample Code: How to prevent character input in a Rich InputText field

To filter user entries in an input text field - e.g. allowing numeric entries only - you can use JavaScript called from an af:clientListener

<af:inputText id="it25" simple="true"
     value="...">
    <af:clientListener method="numbersOnly"
     type="keyDown"/>
</af:inputText>

The JavaScript function then needs to be added to the page as shown below. Adding a JavaScript function is through the af:resource tag, which can contain the JavaScript code in its tag body, or reference it in an external JS file

function numbersOnly(evt){
     var _keyCode = evt.getKeyCode();
     var _filterField = evt.getCurrentTarget();
     var _oldValue = _filterField.getValue();
            
     //check for characters
     if (_keyCode > 64 && _keyCode < 91){  
       _filterField.setValue(_oldValue);
       evt.cancel();	
     }
}


Comments:

Post a Comment:
Comments are closed for this entry.
About

A blog on Oracle JDeveloper, ADF, MAF, MCS and other mobile and web topics inspired by questions and answers posted on the OTN forums.



Frank Nimphius

Search

Archives
« April 2015
SunMonTueWedThuFriSat
   
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
  
       
Today