You need to sign in to do that
Don't have an account?
Praveen525
How to show visual force error
Hi friends,
This is Praveen, is there any way to show field level validation error (Same line) like above shown image using visual force. If it's possible can you please share one example with me to solve my issue?
Thanks & Regards,
Praveen
Hi praveen ,
You can try like this may be it's help ful to you..
<apex:page standardController="Account">
<apex:form >
<apex:pageBlock >
<apex:pageBlockButtons >
<apex:commandButton value="Save" action="{!Save}"/>
<apex:commandButton value="Cancel" action="{!Cancel}"/>
</apex:pageBlockButtons>
<apex:pageBlockSection title="Student Info">
<apex:inputField value="{!Account.Name}"/>
<apex:inputField value="{!Account.AccountNumber}" required="True"/>
<apex:inputField value="{!Account.AnnualRevenue}" required="True"/>
<apex:inputField value="{!Account.Description}" required="True"/>
<apex:inputField value="{!Account.Site}" required="True"/>
</apex:pageBlockSection>
</apex:pageblock>
</apex:form>
</apex:page>
Thanks for your replay,
i tried that one, but our team wants those validation errors at same line as i shown in the image. is there any way to show the error message in the same line using visualforce.
Thanks & Regards,
Praveen
Premnath's code would achieve your purpose except that it would give the error message as Error: You must enter a value. I think this hould suffice your purpose.
But if you need a custom message, you can use JQuery or any javascript to validate the form on submission. And to have the error reported in the same way you have shown in your post, you can use one column table and do the styling accordingly.
Let me know if you need any code snippet.
Regards
Saissreenee
If you investigate the output css I think you'll see they are <span> elements with a certain css class, you can extend css rules for that class using !important. Changing the location will take a bit more work than changing the style, but this can get you on your way:
This link might help you:
http://www.mkpartners.com/blog/apex-code/required-field-and-custom-error-messages-in-visualforce and add style to your page.
Regards,
Taani
As per Taani said you can try this code
<apex:page controller="exampletest">
<apex:form >
<apex:pageBlock >
<apex:pageBlockButtons >
<apex:commandButton value="Save" action="{!save}" />
</apex:pageBlockButtons>
<apex:pageBlockSection >
<apex:pageBlockSectionItem >
<apex:outputLabel value="Required Field" />
<apex:outputPanel styleClass="requiredInput" layout="block" >
<apex:outputPanel styleClass="requiredBlock" layout="block"/>
<apex:inputText value="{!requiredFieldName}" />
</apex:outputPanel>
</apex:pageBlockSectionItem>
<apex:pageMessages />
</apex:pageBlockSection>
</apex:pageBlock>
</apex:form>
</apex:page>
public class exampletest {
public String requiredFieldName {get;set;}
public void save(){
if ( requiredFieldName == null || requiredFieldName == '' ){
ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.ERROR, 'Please enter a value in the Required Field'));
}
}
}
Good Work Taani..........
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
5. make changes according to your vfpage.
6. Then you will get the desired output
Refer Here: http://th3silverlining.com/2010/03/02/visualforce-form-validation-enhanced/#more-543