You need to sign in to do that
Don't have an account?

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 required = true 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
<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.
All Answers
<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.
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:
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