Skip to Content
0

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

Jul 17, 2017 at 05:22 AM

68

avatar image

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

10 |10000 characters needed characters left characters exceeded
* Please Login or Register to Answer, Follow or Comment.

1 Answer

Ivan Dimitrov Oct 04, 2017 at 06:59 AM
0

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

Share
10 |10000 characters needed characters left characters exceeded