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
HeenaHeena 

Required red Mark on a visualforce page

Hi All,

 

I have a visualforce page which has some input fields displayed in it.

These fields are not present in the database. I want to get the red mark on this fields that Salesforce has for required field.

 

I have seen that the red mark appears when we use standard controller and display standard field with requiredtrue in the field attribute. But in my case the fields are not a part of the database

 

Does visualforce has any inbuilt attribute to display the red mark or should I get it as an image myself?

 

 

Thanks & Regards,

Heena 

Best Answer chosen by Admin (Salesforce Developers) 
Rajesh ShahRajesh Shah

<apex:pageBlockSectionItem >
<apex:outputLabel value="Status" for="Status"/>
<apex:outputPanel styleClass="requiredInput" layout="block">
<apex:outputPanel styleClass="requiredBlock" layout="block"/>
<apex:selectList id="chooseStatus" value="{!Contact_Exemption_ACU__c.Status__c}" size="1" required="true" >
<apex:selectOption itemValue="Approved" itemLabel="Approved"/>
<apex:selectOption itemValue="Closed" itemLabel="Closed"/>
</apex:selectList>
</apex:outputPanel>
</apex:pageBlockSectionItem>

 Hey, above is the code to get the red mark for an reqd attribute. Although I have used an standard field, any field can be used in the value in Select List. Also, if you need to display the error message later,following is the code.

<apex:outputPanel styleClass="requiredInput" layout="block">
<apex:inputField id="ACU_held_in_Customer" value="{!Contact_Exemption_ACU__c.ACU_held_in_Customer__c}"/>
<apex:outputPanel styleClass="errorMsg" layout="block" rendered="{!errorACUheldInCustomer}">
<strong>Error:</strong> {!errorMessage}
</apex:outputPanel>
</apex:outputPanel>

 After doing the validation in the Controller, set the errorACUheldInCustomer to true and set the errorMessage.

Hope this helps.

 

 

 

Message Edited by Rajesh Shah on 02-26-2009 07:55 PM

All Answers

Rajesh ShahRajesh Shah

<apex:pageBlockSectionItem >
<apex:outputLabel value="Status" for="Status"/>
<apex:outputPanel styleClass="requiredInput" layout="block">
<apex:outputPanel styleClass="requiredBlock" layout="block"/>
<apex:selectList id="chooseStatus" value="{!Contact_Exemption_ACU__c.Status__c}" size="1" required="true" >
<apex:selectOption itemValue="Approved" itemLabel="Approved"/>
<apex:selectOption itemValue="Closed" itemLabel="Closed"/>
</apex:selectList>
</apex:outputPanel>
</apex:pageBlockSectionItem>

 Hey, above is the code to get the red mark for an reqd attribute. Although I have used an standard field, any field can be used in the value in Select List. Also, if you need to display the error message later,following is the code.

<apex:outputPanel styleClass="requiredInput" layout="block">
<apex:inputField id="ACU_held_in_Customer" value="{!Contact_Exemption_ACU__c.ACU_held_in_Customer__c}"/>
<apex:outputPanel styleClass="errorMsg" layout="block" rendered="{!errorACUheldInCustomer}">
<strong>Error:</strong> {!errorMessage}
</apex:outputPanel>
</apex:outputPanel>

 After doing the validation in the Controller, set the errorACUheldInCustomer to true and set the errorMessage.

Hope this helps.

 

 

 

Message Edited by Rajesh Shah on 02-26-2009 07:55 PM
This was selected as the best answer
HeenaHeena
Thanks a lot Rajesh :smileyhappy
Cool_DevloperCool_Devloper
Hello Friends,

I am working in a similar scenario where i am using "InputField" field type. I am also giving attribute required="true", but somehow i am unable to get the RED Mark still next to the field.

The code is given below:

Countries

:






Can anyone please let me know why is this so? Am i missing something or is there some bug??

Any help will be really great!!

Many Thanks,
Cool_D