+ Start a Discussion
FacebookFacebook 

Required Mark for a input text field in a visualforce page

Hi,

How can i keep Required mark for an input text  value in a visual force page?Setting required="true" is not working..

 

 Name : <apex:inputtext value="{!ContactName}" id="name"  required="true"/>

 

 

regards,

Abhi

Best Answer chosen by Admin (Salesforce Developers) 
Pradeep_NavatarPradeep_Navatar

Required="true" does not show any required mark it only show error message when filed is blank. You have to use an image that look like that and needs some coding also to show the Required Mark.

 

Secondly you can override the salesforce functionality. Find below a sample code as a workaround :

 

        <apex:page controller="cls_con">

        <apex:form>

        <apex:pageBlock >

        <div class = "requiredInput">

        <div class = "requiredBlock"></div>

        <apex:inputtext value="{!ContactName}"  required="true"/>

        </div>

        </apex:pageBlock>

        </apex:form>

        </apex:page>

All Answers

ministe2003ministe2003

do you mean the red line?

 

Try this:

 

 

<apex:pageBlockSectionItem>
  <apex:outputLabel value="Name" />
  <apex:inputText value="{!ContactName}" id="name" required="true" />
</apex:pageBlockSectionItem>

 

 

Does that look any better?

sravusravu

Are you using a standard controller or custom controller. If you  are using standard controller use <apex:inputfield/> component. You can also write a method in Apex controller to validate if the field has been filled or not before saving the record.

Pradeep_NavatarPradeep_Navatar

Required="true" does not show any required mark it only show error message when filed is blank. You have to use an image that look like that and needs some coding also to show the Required Mark.

 

Secondly you can override the salesforce functionality. Find below a sample code as a workaround :

 

        <apex:page controller="cls_con">

        <apex:form>

        <apex:pageBlock >

        <div class = "requiredInput">

        <div class = "requiredBlock"></div>

        <apex:inputtext value="{!ContactName}"  required="true"/>

        </div>

        </apex:pageBlock>

        </apex:form>

        </apex:page>

This was selected as the best answer
Chirag MehtaChirag Mehta

It worked, thanks!

develpdevelp

It's working, thanks

Saulo Oliveira 6Saulo Oliveira 6
Just to contribute with Pradeep_Navatar answer, below the code using just apex code. It makes all elements became identical to a default visual force page (special attention to specified css classes):
 
<apex:pageBlockSectionItem>
                        <apex:outputLabel value="{!labelCNPJ}"/>
                        
                        <apex:panelGroup styleClass="col02 requiredInput" layout="block">
                            <apex:panelGroup styleClass="requiredBlock" layout="block"/>
                            <apex:inputText value="{!cnpj}" required="true"/>  
                        </apex:panelGroup>
</apex:pageBlockSectionItem>