Skip to main content

Is there an option to restrict the pass dates and say dates after few months in Date picker in VF Page?

Requirement is like a User shouldn't take an Order/Opportunity of past dates and not which belongs to another fiscal month like, For example if a user is saving an Opportunity today he shouldn't save it with past date or August or later month in Close Date.

I tried using jquery as below, But it didnt work. Please let me know if I am making any mistakes.

    <apex:page standardController="Contact">
  <head lang="en">
      <meta charset="utf-8"/>
      <meta name="viewport" content="width=device-width,initial-scale=1.0"/>
      <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.0/jquery.min.js"></script>
  </head>
  <body>
      <apex:form >
          <apex:pageBlock>
          <apex:pageblockSection>
          <apex:inputField id="output1" value="{!Contact.Birthdate}"/>
          </apex:pageblockSection>
          </apex:pageBlock>
      </apex:form>
      <script>
          $("#datepicker").datepicker({ maxDate: new Date, minDate: new Date(2016, 8, 8) });
          alert('Hello, jQuery');
      </script>
  </body>
</apex:page>

Is there an option to restrict the pass dates and say dates after few months in Date picker in VF Page?

Requirement is like a User shouldn't take an Order/Opportunity of past dates and not which belongs to another fiscal month like, For example if a user is saving an Opportunity today he shouldn't save it with past date or August or later month in Close Date.

Is there an option to restrict the pass dates and say dates after few months in Date picker in VF Page?

Requirement is like a User shouldn't take an Order/Opportunity of past dates and not which belongs to another fiscal month like, For example if a user is saving an Opportunity today he shouldn't save it with past date or August or later month in Close Date.

I tried using jquery as below, But it didnt work. Please let me know if I am making any mistakes.

    <apex:page standardController="Contact">
  <head lang="en">
      <meta charset="utf-8"/>
      <meta name="viewport" content="width=device-width,initial-scale=1.0"/>
      <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.0/jquery.min.js"></script>
  </head>
  <body>
      <apex:form >
          <apex:pageBlock>
          <apex:pageblockSection>
          <apex:inputField id="output1" value="{!Contact.Birthdate}"/>
          </apex:pageblockSection>
          </apex:pageBlock>
      </apex:form>
      <script>
          $("#datepicker").datepicker({ maxDate: new Date, minDate: new Date(2016, 8, 8) });
          alert('Hello, jQuery');
      </script>
  </body>
</apex:page>
Source Link
C. Praveenkumar
  • 2.1k
  • 3
  • 26
  • 49

Ability to limit dates/ranges for selection on calendar in a Date field in salesforce

Is there an option to restrict the pass dates and say dates after few months in Date picker in VF Page?

Requirement is like a User shouldn't take an Order/Opportunity of past dates and not which belongs to another fiscal month like, For example if a user is saving an Opportunity today he shouldn't save it with past date or August or later month in Close Date.