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
anil kumar devunoorianil kumar devunoori 

How to make a selectlist field on visualforce page required and behave similar to object field?

I need to add a selectlist on the vf page which has less number of picklist values than actual picklist on the object. I need to make the selectlist required and when the value is not selected the error message should display just below the select list as displayed for object fields.
Surendra nuneSurendra nune
Anil, Please mark it as best answer if it resolves your problem.


 
Keyur  ModiKeyur Modi

Hi anil,

<apex:pageMessages />
<apex:selectList value="{!selectedSobject}" required="true" multiselect="false" size="1" >
            <apex:selectOption itemValue="Account" itemLabel="Accounts"/>
            <apex:selectOption itemValue="Contact" itemLabel="Contacts"/>
            <apex:selectOption itemValue="Opportunity" itemLabel="Opportunity"/>
        </apex:selectList>

use this bunch of code it will help you. it will make selected list and it will required also if user will not select the value it will give error value is required.