Reputation: 1226
I am trying to add an inline minDate on a datePicker in SAPUI5.
I have tried:
Fragment
<DatePicker id="PurchaseDateFromId" value="" minDate="{ new Date(); }"/>
<DatePicker id="PurchaseDateFromId" value="" minDate="{ todayDate }"/>
Controller
var todayDate = new Date();
Neither work and the console states that it must be a JS object.
Upvotes: 1
Views: 4538
Reputation: 1145
Maybe these examples help you out.
View 1
<DatePicker minDate="{dateModel>/minDate}" />
Controller 1
onInit: function() {
var oModel = new sap.ui.model.json.JSONModel( {
minDate: new Date()
});
this.getView().setModel(oModel, "dateModel");
}
View 2
<DatePicker id="PurchaseDateFromId"/>
Controller 2
onInit: function() {
this.byId("PurchaseDateFromId").setMinDate(new Date());
}
Upvotes: 4
Reputation: 2256
You can achieve it by setting maxDate
and minDate
properties of sap.m.DatePicker
after loading fragment in controller.
Controller
//Fragment loaded
var oPurchaseDt = this.getView().byId("PurchaseDateFromId");
if (oPurchaseDt) {
var oPurchaseMaxDate = '';//update max date
var oPurchaseMinDate = new Date();
oPurchaseDt.setMaxDate(oPurchaseMaxDate);
oPurchaseDt.setMinDate(oPurchaseMinDate);
}....
Fragment
<DatePicker id="PurchaseDateFromId" value=""/>
Note: If the maxDate
is set to be before the minDate
, the maxDate
and the minDate
are switched before rendering.
Upvotes: 1