Skip to Content

Uncaught TypeError: Cannot read property 'apply' of undefined(sap.m.DatePicker)

Dear All,

I override the java script Date() method to override system date and time from server date and time. The date picker is defaulted with server date but the problem is the datepicker dialog is not opening.

Date = function (Date) {

     MyDate.prototype = Date.prototype;

     return MyDate;

     function MyDate() {

         return currentServerDate;  //currentServerDate is my server date

     }

  }(Date);

I'm getting this below error,

Uncaught TypeError: Cannot read property 'apply' of undefined

(anonymous function) @ UniversalDate.js:6

c.init @ Calendar.js:6

E.extend.constructor @ sap-ui-core.js:152

M.extend.constructor @ sap-ui-core.js:152

E.extend.constructor @ sap-ui-core.js:152

f @ sap-ui-core.js:152

o @ sap-ui-core.js:143

_ @ DatePicker.js:6

b @ DatePicker.js:6

a.onclick @ DatePicker.js:6

a._callEventHandles @ sap-ui-core.js:152

a._handleEvent @ sap-ui-core.js:152

U._handleEvent @ sap-ui-core.js:152

p @ sap-ui-core.js:60

Q.event.dispatch @ sap-ui-core.js:71

v3.handle @ sap-ui-core.js:71

For working Date picker below .js are loading in network tab.

Calendar.js

CalendarUtils.js

Header.js

Month.js

MonthPicker.js

YearPicker.js

DateRange.js

CalendarRenderer.js

messagebundle_en_US.properties

HeaderRenderer.js

MonthRenderer.js

MonthPickerRenderer.js


But In this overriding case below .js are loading.

Calendar.js

CalendarUtils.js

Header.js

Month.js

MonthPicker.js

YearPicker.js

Please help me to resolve this.

Thanks,

Santhosh Gowda

Add comment
10|10000 characters needed characters exceeded

  • Get RSS Feed

3 Answers

  • Best Answer
    Oct 26, 2015 at 08:25 AM

    The overridden Date constructor doesn't have the date methods UTC, parse, now. The code in the framework breaks when it's trying to access one of the method. But I don't think even adding those methods to the overridden Date could give you a complete working Datepicker. I think its a bad idea to override the Date constructor as a solution for this

    Add comment
    10|10000 characters needed characters exceeded

  • Nov 05, 2015 at 11:22 AM

    Hello Santosh,

    Would like to know the scenario, why do you want to display current date from server date ? Because if the client's date is 5 Nov and it’s going to highlight probably  4 or 6 which would be then a wrong indication for the client.

    Anyways

    Option 1 : Get rid of the current date border completely using css by overriding the main css class.

    .sapUiCalDayToday>.sapUiCalDayNum { border: none !important; line-height: 2.6875rem; } 

    Your users will not be confused with current date border, and anyway you set the server date as default date.

    Option 2 : Overriding the Date Picker method would not help, the highlight I guess comes from sap.ui.unified.calender.Month.js and it would not be simple to do it as the variable is set at many places using (new Date).

    Option 3:  Overriding CSS might can only be a temporary workaround as you rightly said should be your last option, but in my opinion too not a good clean way as also mention by others.   

    Regards,

    Vasu

    Add comment
    10|10000 characters needed characters exceeded

    • The 'today' date is determined in the sap.ui.unified.calendar.MonthRenderer class;

      a helper object 'oHelper' is created with property 'oToday' which holds the current client date:

      MonthRenderer.getDayHelper = function(oMonth, oDate){
        var oHelper = {};
        ....
        oHelper.oToday = CalendarUtils._createUniversalUTCDate(new Date());
        ....
        return oHelper;
      };
      

      Upon iterating through the month days, a check is done to see if the day matches today, and then the border class is applied:

      if (oDay.getUTCMonth() == oHelper.oToday.getMonth() && oDay.getUTCFullYear() == oHelper.oToday.getFullYear() && oDay.getUTCDate() == oHelper.oTo day.getDate()) {
        oRm.addClass("sapUiCalDayToday");
        mAccProps["label"] = oHelper.sToday + " ";
      }
      

      So I guess you somehow need to override the MonthRenderer.getDayHelper method, but not sure if this can be done easily

  • Oct 29, 2015 at 06:24 AM
    Add comment
    10|10000 characters needed characters exceeded

    • "setDateValue" is setting the date value but in sap.m.datepicker purple color highlighting is based on system date.

      so i setDateValue with currentServerDate but i'm not able to do "purple color highlighting" with currentServerDate.

      may be  "sap/ui/unified" calendar - lib's are taken care of this highlighting DatePicker But still failing to find out.