Thursday, July 31, 2014

Clearing default af:inputDate error message


This post gives simple idea on clearing the error message on adf components. By default  af:inputDate component having issue while showing the error message for invalid input.

For example : If you give invalid date, a popup message will be shown with error message as shown below. Then again click the datepicker icon to select the date, the error message in the popup will show multiple times. If you click the datepicker 10 times, 10 times same error message will be shown. Look at the below screen,

 


To clear the message shown multiple times, use the below javascript,
    
<af:resource type="javascript">

        function cleardatemsg(evt) {

            var comp = evt.getSource();

            AdfPage.PAGE.clearMessages(comp.getClientId());

        }

   </af:resource>


Note:  
comp.getClientId() - will give the exact component Id. When your application have Template, the component Id will be like this pt1:id1 where pt1 - template Id and id1 - date component Id
evt.getId() -  will give only id1 as component Id even if its inside the template.

Call the javascript method on click event like below,

<af:inputDate label="Label 1" id="id1">

         <af:clientListener method="cleardatemsg" type="click"/>

 </af:inputDate>


Use this line to clear All the error messages in the form

AdfPage.PAGE.clearAllMessages();


For more details about error messages and tips, go through this link  http://docs.oracle.com/cd/E17904_01/web.1111/b31973/af_message.htm