Friday, 17 August 2012

How to disply custom client-side error messages on VF pge

Custom Error Messages on VF page

How to dipaly client side error messages like above?
 By using jquery you can diplay error messages as you mentioned in the above image
1. First download the jquery file here.
2. If it is not downloading copy the code and paste it in notepad and save it with jquery.js like that.
3. Then upload that file into static resources.
4. In your vf page use the following code
<apex:page standardcontroller="Account" showHeader="false" standardStylesheets="false">
    <apex:includeScript value="{!$Resource.jquery}"/>
    <apex:includeScript value=""/>
    <script type="text/javascript"> 
        $(document).ready(function() {
                required: true,
                minlength: 5
                required: true,
                email: true
                url: true
                required: true
                required: true,
                minlength: 5
                required: true,
                minlength: 5,
                equalTo: '[id$=pwd]'
            /* Customised the messages */
            jQuery.validator.messages.required = "You better have entered a value.. or else!"; 
            jQuery.validator.messages.equalTo = "No silly, you're supposed to type the same set of characters AGAIN.";                                                
    <!-- Ignore my template -->
    <apex:composition template="Template">
        <apex:define name="title">
            <a href="">jQuery Forms Validation Demo</a>
        <apex:define name="blurb">
                Fiddle with the form entering combinations of correct and incorrect values to see the validation rules in action. Hitting the sumbit button will also trigger form checking.

        <apex:define name="content">    
            <apex:outputPanel layout="block" style="text-align:center; font-size:12px;padding: 4px">
                <apex:form id="commentForm" > 

                        <apex:outputlabel for="name">Name <span class="star">*</span></apex:outputlabel> 
                        <apex:inputtext id="name" value="{!}"/>
                        <apex:outputlabel for="email">E-Mail <span class="star">*</span></apex:outputlabel> 
                        <apex:inputtext id="email"  value="{!}"/> 
                        <apex:outputlabel for="url">URL (optional)</apex:outputlabel> 
                        <apex:inputtext id="url"  value="{!}" /> 
                        <apex:outputlabel for="comment">Your comment <span class="star">*</span></apex:outputlabel> 
                        <apex:inputtextarea id="comment" value="{!}" style="width: 30%"/>
                        <apex:outputLabel for="pwd">Password <span class="star">*</span></apex:outputLabel>
                        <apex:inputSecret id="pwd" value="{!}"/>
                        <apex:outputLabel for="cpwd">Confirm Password <span class="star">*</span></apex:outputLabel>
                        <apex:inputSecret id="cpwd" value="{!}"/>                        
                        <input type="submit" />
5. make changes according to your vfpage.
6. Then you will get the desired output
Refer Here:

No comments:

Post a Comment