function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion

inputField error message

Hi Friends,


Please help me out,


I am using required inputFields a Visual Force Page with standardController Object .

I am refereshing each input field for onblur event in order validate the field immidiately.


The problem, i dont want to have default error message Error: You must enter a value


 I dont want to remove the required attribute , as i need to have the required field symbol.


Please let me if there is any work around for this:






Message Edited by yvk431 on 01-05-2010 05:55 AM
Best Answer chosen by Admin (Salesforce Developers) 
There's markup for adding the required bar on this blog page.

All Answers


So is the problem that you are submitting the form back to get the field validated on entry, but this is resulting in other required fields being flagged up as empty?


If that is the case, check out actionRegion - this allows you to restrict the fields that are submitted back to a controller method.




No it is not,


Let say , i have only one inputField (text field) , i want to show a custom error message for onblur event

for this using action support i am calling a pageReference method to validate for some regex expression.


If I remove the required attribute , I am able to get my custom error message, but by doing so,

the mandatory  flag was also getting removed  which I dont want to happen


Please check following code


VFP code


<apex:page standardController="Users__c" extensions="saveRegUser">
<apex:pagemessages ></apex:pagemessages>
<apex:form >
<apex:pageBlock >
<apex:pageBlockSection id="pbs1" columns="2">

<apex:inputField value="{!Users__c.b_First_Name__c}" id="firstname" style="width:150px" required="true" >
<apex:actionSupport event="onblur" rerender="pbs1" action="{!fetchFName}" status="fnStatus"/>
<apex:outputPanel >
<apex:image value="{!$Resource.checker}" rendered="{!(fnamechk == true)}" id="fnamechk"/>
<apex:outputText value="{!fnameerrormsg}" id="firstnamecheck" style="color:red" />


<apex:actionStatus id="fnStatus" startText="Fetching First Name ....." stopText="" >
<apex:facet name="start">
<image src="{!$Resource.spinner}" ><font color="black">Verifying First Name...</font></image>




 Apex code



public class saveRegUser
private final ApexPages.standardController theController;
private final Users__c usernew ;
public string fname{get; set;}
public boolean fnamechk{get; set;}
public string fnameerrormsg{get; set;}

public saveRegUser(ApexPages.StandardController regUserController)
this.usernew = (Users__c)regUserController.getrecord();


public pageReference fetchFName()
fname = usernew.b_First_Name__c;
Pattern firname;
Matcher firmatcher ;
if(fname != null){
firname = Pattern.compile('(?=.*[^A-Za-z0-9 _.-]).*$');
firmatcher = firname.matcher(fname);
if(fname == null || fname.trim().length() == 0 )
fnameerrormsg = 'First Name cannot be blank or white space';
fnamechk = false;
else if(firmatcher.find() )
fnameerrormsg = 'Only letters, numbers, spaces and hyphens are allowed';
fnamechk = false;
fnameerrormsg = '';
fnamechk = true;

return null;






Message Edited by yvk431 on 01-05-2010 09:13 AM

From your example below, it looks like the validation isn't databound--that is, that you can check the name without access ot other data. This makes it a prime candidate for *redundant* validation in Javascript, which will, I think, get you the effect you want. Here's what to do:


1. Instead of using an actionSupport for onBlur, just call a Javascript function from the component's onBlur attribute that validates the data and displays the error message if validation fails.

2. Since Javascript isn't secure, you *do* still need to do server-side validation of the field as well (since a malicious user can get around your Javascript). But *that* can wait until page submit time--the only reason you want to provide immediate feedback is for user convenience, and you don't have to worry about the convenience of malicious users.


This lets you use your own error message; users will only see the "standard" message if they for some reason disable your Javascript.


Hope this helps,



PS: ...oops, I see that you *do* need to render another field depending on whether the check succeeds, so you do need to make a round-trip to the server immediately, *if* your JS passes. But you can still use the same basic technique.


Message Edited by Avrom on 01-05-2010 09:55 AM
You can add the red bar that indicates a mandatory field through divs and styling.  I have done this in the past by inspecting the HTML source of the page with the red bar generated and replicating this into my VF page.  That way you can have the visual indicator that a field is mandatory, but not have the associated automatic validation.

Thanks Bob and Avrom,


I just want to know is there any work around to override the default required message.


Also if I introduce the div tag any other tag for input field ,  the label will get disappear 

and i need to  define the label explicitly, anyways thanks for the help.


I don't think there is any way to override the default messages - certainly I've never come across anything to allow that.


The only other thing I can think of to look into is the translation side of things, though I think that would still only let you change one generic message for another generic message. 


Thank you for your patience Bob


I've achieved it partially by removing the required attribute and using the style attribute as below


<apex : inputField value="{!Users__c.b_First_Name__c}" id="firstname" style="height:20px;width:150px;border-left: medium solid red"  /> 



Though this still have some alignment issues and the mark doesn't look like the same as the standard one.

I am with this for now



There's markup for adding the required bar on this blog page.
This was selected as the best answer
Erik HeibergErik Heiberg
While Shikibu's (linked) solution above will work, you can also just embed the inputfield inside a couple divs as well.


<div class="requiredInput">
   <div class="requiredBlock" />
   <apex:inputField value="{!sampleControllerOrExtensionParameter}" />