Thursday, May 5, 2016

Disabling the browser form auto-complete

Disabling the browser form auto-complete

As often, somebody's heaven is another one's hell. The browser auto-complete functionality is one example for this. In Oracle ADF Faces, there is no property that switches auto complete-off for input field components or the af:formcomponent. Thanks to the ADF Faces client side architecture switching off this browser functionality is easy to achieve:
<af:form> 
  
  <af:clientListener  type="mouseOver"
                      method="suppressAutoComplete"/>
</af:form>
The mouse over event is issued one time when you enter a form. Given that you can only have a single form on a page, this means it fires one time for the page.
The JavaScript function referenced by the af:clientListener element is shown below
function suppressAutoComplete(evt){
 var domElement =
     AdfRichUIPeer.getDomContentElementForComponent(evt.getSource());
 domElement.setAttribute("autocomplete", "off" ); 
}
If you put this into a JS library that you reference from the af:resource tag then all you need to remember is add the af:clientListener tag to the af:form tag.

No comments:

Post a Comment