1

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 !

1

You 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>
  • 1
    also (and not necessarily better) - Keir Bowden's VF Development Cookbook pg83-85 shows how to do this using Design2Develop.com/calendar - a JS custom datepicker – cropredy Apr 24 '15 at 1:32
  • It shows error Unsupported attribute class in <apex:inputText> in OM_SubscriptionActivate – Sparrkli Apr 24 '15 at 12:19
  • @Sparrkli Yeah sorry, it should be styleClass. – Adrian Larson May 6 '15 at 14:56
0

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.