Skip to Content

Allowing selection of current and future dates only in sap.m.DatePicker control of sapui5

Hi Experts,

I have a requirement where i am using sap.m.Datepicker object and i have to allow selection of current and future dates only. Past Date values should be grayed out. I have tried

minDate property but it's not allowing user to select present date. Only future date selection is possible.

My Code is as follows--

Date.prototype.yyyymmdd = function() {
							  var mm = this.getMonth() + 1;                  // getMonth() is zero-based
							  var dd = this.getDate();


							  return [
							          (dd>9 ? '' : '0') + dd,
							          (mm>9 ? '' : '0') + mm,
							          this.getFullYear()
							         ].join('.');
							};




var dateSelect =  new sap.m.DatePicker(
													"dp_vesselArrDate",
													{
														
														
														width : "250px",
														displayFormat : "dd.MM.yyyy",
														valueFormat : "dd.MM.yyyy",
														minDate: 

yyyymmdd

, change : function( oControlEvent) { this .setValueState(sap.ui.core.ValueState.None); if (this.getValue() === "") { this .setValueState(sap.ui.core.ValueState.Error) } } }),

Add comment
10|10000 characters needed characters exceeded

  • Get RSS Feed

1 Answer

  • Oct 04, 2017 at 06:59 AM

    Hi,

    you can use the following:

    minDate="{customModel>/currentDate}"

    where customModel is:

        var model = new JSONModel({
            currentDate: new Date()
        });
    

    And I initialize the model in the Component.js

    And for your particular case you can use:

    minDate: new Date()

    when you initialize the control.

    KR,

    Ivan

    Add comment
    10|10000 characters needed characters exceeded