cancel
Showing results for 
Search instead for 
Did you mean: 

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

0 Kudos

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) } } }),

Accepted Solutions (0)

Answers (1)

Answers (1)

idim
Explorer
0 Kudos

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

0 Kudos

Thank u ..