+ Start a Discussion
meyerdmeyerd 

selectList required="true" no red bar on Visualforce Page

I have a visual force page that gets select options from a controller.
I have required="true" for the selectList.
No red bar shows on the page when it is displayed.
If I don't select a value and submit the form.
I do not get a message on the field 'You must enter a value' like I do on other fields required in the same way, but do get informed in  apex:pageMessages mentioning

thePage:theForm:j_id1:j_id5:0: Validation Error: Value is required.

The field is a multiselect picklist which I am showing on the VF page as a selectList size 1 only when the user has not previously selected values for that field.

Code:
<apex:page standardController="Opportunity" recordSetVar="opportunities" sidebar="false" showHeader="true" extensions="OpptyMultiEdit_CTE" id="thePage">
......
<apex:pageBlockTable value="{!OpptyList}" var="oppty" cellpadding="4" headerClass="TH_Class">
......
<apex:selectList required="true" size="1" value="{!oppty.Competitors__c}">
<apex:selectOptions value="{!CompetitorsPicklist}"/>
</apex:selectList>



Opportunity[] Opptys;
public List<Opportunity> getOpptyList()
{
return Opptys;
}

public List<SelectOption> getCompetitorsPicklist()
{
List<SelectOption> options = new List<SelectOption>();
Schema.DescribeFieldResult f = Opportunity.Competitors__c.getDescribe();
String defValue = '';
options.add( new SelectOption( '', '--None--'));
for(Schema.PicklistEntry pe : f.getPicklistValues())
{
if ( pe.getValue() != Competitors )
{
options.add( new SelectOption( pe.getValue(), pe.getLabel() ));
}
}
return options;
}

Ideas on
-why the red bar not showing?
-why is the field not being Highlighted and marked with 'Error: You must enter a value' when I submit the form?





jwetzlerjwetzler
The red bar and salesforce error messaging only applies to inputField which is a standard salesforce component that inherits salesforce formatting and behavior.  There are many many posts about this on the forums.  It would not be appropriate for us to dictate how your requiredness rules work if you are not using inputField, so therefore if you must use selectList then you must handle requiredness yourself.  The only thing that required="true" will do is add a message to your messaging component and prevent the form from successfully submitting.
meyerdmeyerd
Thanks for the quick response.
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
JPlayEHRJPlayEHR

Do you have your <apex:inputField/> inside of an <apex:PageBlockSection> ?