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
Kunlun liKunlun li 

Is possible to add "Required" highlight style to visual force component except <apex:inputField?

Hi All

 

I know we can wirte code as <apex:inputField required="true"/> to make this field required highlight and checking.

 

Can we make code same style for other component? such as <apex:selectList>, <apex: inputText>

 

I wrote as <apex:selectList required="true"/>, but no required highlight on visualforce page.

 

Anyone can help me?

 

Thanks

Kunlun

Best Answer chosen by Admin (Salesforce Developers) 
abhishektandon2abhishektandon2

Add your style using output panel to make that field look like required

 

<apex:outputPanel styleClass="requiredInput" layout="block" >
<apex:outputPanel styleClass="requiredBlock" layout="block"/>
<apex:selectList id="productNameValue" disabled="false" multiselect="false" value="{!productDetails.oli.pricebookEntryId}" size="1">
<apex:selectoptions value="{!products}" />
</apex:selectList> 
</apex:outputPanel>

 

All Answers

abhishektandon2abhishektandon2

Add your style using output panel to make that field look like required

 

<apex:outputPanel styleClass="requiredInput" layout="block" >
<apex:outputPanel styleClass="requiredBlock" layout="block"/>
<apex:selectList id="productNameValue" disabled="false" multiselect="false" value="{!productDetails.oli.pricebookEntryId}" size="1">
<apex:selectoptions value="{!products}" />
</apex:selectList> 
</apex:outputPanel>

 

This was selected as the best answer
KunlunKunlun

Thanks very much. It works for me.

Siddharth Birari.ax1164Siddharth Birari.ax1164
Would it work for <apex:selectRadio/> as well?
I tried with the above provided code but didn't work for me?
Is it compulsory to have such code inside a pageBlock or a pageBlockSectiom