Tim Malich Tim Malich - 1 year ago 898
Javascript Question

SAPUI5 Datepicker read only

Does anyone know how to make the SAPUI5 control sap.m.DatePicker read only? I would like to be able to show the standard calendar UI to the user if he clicks on the little calendar icon but the user shouldn't be allowed to actually change the date.

The only workaround I found so far is to attach a function to the change event and reset the value property to the original value. But that's neither good nor pretty.

Here's a little JSBin example with a DatePicker.

jQuery(function() {
var picker = new sap.m.DatePicker();

// is there a better solution than this: `??????
oEvent.getSource().setDateValue(new Date())



Answer Source

Overriding the .setDateValue() method for your instance will disable the date selection.

sap.m.DatePicker source code on github is worth a look.

  var picker = new sap.m.DatePicker(); 
  picker.setDateValue = function() {};


Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download