So I would like to disable for user to choose future date in datepicker
<apex:inputfield value="{!currService.csord__Activation_Date__c}" required="true"/>
Thank you for the help !
Salesforce Stack Exchange is a question and answer site for Salesforce administrators, implementation experts, developers and anybody in-between. It only takes a minute to sign up.
Sign up to join this communityYou can do this with JQuery UI Datepicker [documentation], so this is essentially a duplicate of this question on StackOverflow.
Specifically, you will probably want to specify maxDate
[documentation]. You can use more complicated blacklisting/whitelisting schemes by defining a beforeShowDay
method [documentation] but that seems like overkill for your requirements. You will need to use apex:inputText
instead and bind it to your controller differently.
Controller:
public String daySelected { get; set; }
public String dateSelected
{
get
{
return Date.valueOf(day); // add try/catch somewhere, but not in your getter
}
}
public SObject myRecord
{
get
{
return new Custom_Object(Custom_Date__c = dateSelected);
}
}
VisualForce:
<apex:stylesheet value="https://code.jquery.com/ui/1.9.2/themes/base/jquery-ui.css" />
<apex:stylesheet value="https://code.jquery.com/ui/1.11.2/themes/smoothness/jquery-ui.css" />
<apex:inputText styleClass="customDatePicker" value="{!daySelected }" />
<script src="https://code.jquery.com/jquery-1.11.2.min.js" />
<script src="https://code.jquery.com/ui/1.11.3/jquery-ui.min.js" />
<script>
(function (w, $) {
"use strict";
$('.customDatePicker').datepicker([
maxDate: new Date()
]);
})(window, jQuery.noConflict());
</script>
The best way would be to just check the date in the save method and put an error on the page if it is after Date.today().
In order to completely disable future dates you would have to use Javascript, possibly replacing the picker all together. Generally not worth the effort.