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
Matt Cooper 7Matt Cooper 7 

Adding/defaulting a null value to a selectlist picklist on a Visualforce page

I am creating a VF page that basically has different "pages" that each have different questions on them. Each "page" is a different outputpanel that is rendered depending on clicking a Continue or Back button. I have created a few picklists using selectList/selectOption to make other questions appear or not. The problem I'm running into is that I want to make these picklists required before being able to move to the next page, but I can't seem to do so because there is no null option. I would like the picklist to start as null which would make the user choose one of the options before they can continue.
For example, with the following code snippet, I can create a picklist on the page with all the options, but the user can just move to the next page without making a choice.
Class:
public List < SelectOption > getisNDA() { List < SelectOption > options3 = new List < SelectOption > (); List < String > tempList = new List < String > (); tempList.add('Yes'); tempList.add('No'); for (String s: tempList) options3.add(new SelectOption(s, s)); return options3; }


Page:
<apex:selectList id="sel3" value="{!NDA2}" multiselect="false" size="1" tabIndex="70" styleclass="inputc" required="true"> <apex:actionSupport event="onchange" action="{!NDAupdate}" rerender="NDAQ1, NDAQ2" /> <apex:selectOptions value="{!isNDA}" /> </apex:selectList>

 
GauravGargGauravGarg
Hi Matt,

Please add one more value in Selection option as "None".  

templist.add(' None ');

This might works as you default value. 

Hope this will help you. Let me know if you still face issues.

Thanks,
Gaurav
email: gauravgarg.nmims@gmail.com
skype: gaurav62990