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
Cable Guy.ax375Cable Guy.ax375 

Disable the past months in the dropdown

I need to disable the past months in the dropdown so that user can only select the current month and future month as the criteria for searching on Visual Force page. Any help will be greatly appreciated. 

 

<apex:selectList value="{!month}" multiselect="false" size="1">
<apex:selectOption itemValue="1" itemLabel="January" />
<apex:selectOption itemValue="2" itemLabel="February" />
<apex:selectOption itemValue="3" itemLabel="March" />
<apex:selectOption itemValue="4" itemLabel="April" />
<apex:selectOption itemValue="5" itemLabel="May" />
<apex:selectOption itemValue="6" itemLabel="June" />
<apex:selectOption itemValue="7" itemLabel="July" />
<apex:selectOption itemValue="8" itemLabel="August" />
<apex:selectOption itemValue="9" itemLabel="September" />
<apex:selectOption itemValue="10" itemLabel="October" />
<apex:selectOption itemValue="11" itemLabel="November" />
<apex:selectOption itemValue="12" itemLabel="December" />

 

SSRS2SSRS2

Use following class for your VF page

 

VF page:

<apex:page controller="DateSample">
 <apex:form>
    <apex:selectList value="{!month}" multiselect="false" size="1">
        <apex:selectOption itemValue="1" itemLabel="January" itemDisabled="{!Jan}"/>
        <apex:selectOption itemValue="2" itemLabel="February" itemDisabled="{!feb}"/>
        <apex:selectOption itemValue="3" itemLabel="March" itemDisabled="{!mar}"/>
        <apex:selectOption itemValue="4" itemLabel="April" itemDisabled="{!apr}"/>
        <apex:selectOption itemValue="5" itemLabel="May" itemDisabled="{!may}"/>
        <apex:selectOption itemValue="6" itemLabel="June" itemDisabled="{!jun}"/>
        <apex:selectOption itemValue="7" itemLabel="July" itemDisabled="{!jul}"/>
        <apex:selectOption itemValue="8" itemLabel="August" itemDisabled="{!aug}"/>
        <apex:selectOption itemValue="9" itemLabel="September" itemDisabled="{!sep}"/>
        <apex:selectOption itemValue="10" itemLabel="October" itemDisabled="{!oct}"/>
        <apex:selectOption itemValue="11" itemLabel="November" itemDisabled="{!nov}"/>
        <apex:selectOption itemValue="12" itemLabel="December" itemDisabled="{!dec}"/>
    </apex:selectList>
  </apex:form>
</apex:page>

 

 

Apex class:

 

public with sharing class DateSample {
    public String dec { get; set; }
    public String nov { get; set; }
    public String oct { get; set; }
    public String sep { get; set; }
    public String aug { get; set; }
    public String jul { get; set; }
    public String jun { get; set; }
    public String may { get; set; }
    public String apr { get; set; }
    public String mar { get; set; }
    public String feb { get; set; }
    public String Jan { get; set; }
    
    public String month { get; set; }
    String[] monthArray;
    
    public DateSample () {
      Integer monthInt = System.Now().month();//8
     
      monthArray = new  String[]{ 'jan',
                                  'feb',
                                  'mar',
                                  'apr',
                                  'may',
                                  'jun',
                                  'jul',
                                  'aug',
                                  'sep',
                                  'oct',
                                  'nov',
                                  'dec' };
                              
     for (integer i = 0; i<monthInt; i++) {
       if (monthArray[i]=='jan') {
         jan = 'true';
       }
       if (monthArray[i]=='feb') {
         feb = 'true';
       }
       if (monthArray[i]=='mar') {
         mar = 'true';
       }
       if (monthArray[i]=='apr') {
         apr = 'true';
       }
       if (monthArray[i]=='may') {
         may = 'true';
       }
       if (monthArray[i]=='jun') {
         jun = 'true';
       }
       if (monthArray[i]=='jul') {
         jul = 'true';
       }
       if (monthArray[i]=='aug') {
         jul = 'true';
       }
       if (monthArray[i]=='sep') {
         sep = 'true';
       }
       if (monthArray[i]=='oct') {
         oct = 'true';
       }
        if (monthArray[i]=='nov') {
         nov = 'true';
       }
       if (monthArray[i]=='dec') {
         dec = 'true';
       }
     }
    }
}

 

 write method for set selected month(enabled month) using follow code stuff

 

 Integer monthInt = System.Now().month();

 -Suresh