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

The Oracle JDeveloper forum ranks in the Top 5 of the most active forums on the Oracle Technology Network (OTN).



The OTN Harvest blog is a summary of selected topics posted on the OTN Oracle JDeveloper forum.



It is an effort to turn knowledge exchange into an interesting read for developers who enjoy little nuggets of wisdom





Frank Nimphius

Search

Archives
« April 2014
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