Tim Malich Tim Malich - 5 months ago 409
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();
picker.detachEvent("change");

// is there a better solution than this: `??????
picker.attachChange(function(oEvent){
oEvent.getSource().setDateValue(new Date())
});

picker.placeAt('content');
});


http://jsbin.com/racoje/edit?html,js,console,output

Answer

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() {};

http://jsbin.com/yirademuwa/1/edit?html,js,output

Comments