fioricddev / tickets

0 stars 0 forks source link

Date picker can not display after value set #1

Open fioricddev opened 8 years ago

fioricddev commented 8 years ago
Description
<DatePicker id="datePickerStartDate" displayFormat="medium"></DatePicker>
this.byId('datePickerStartDate').setValue(cus.crm.opportunity.util.Formatter.dateFormatter(new Date()));
dateFormatter: function (oValue) {
        if(oValue === "" || oValue === null || oValue === undefined)
            return "";

        if(!(oValue instanceof Date)){
             oValue = new Date(oValue);
        }

      //    oValue.setMinutes(oValue.getTimezoneOffset());

        var locale = new sap.ui.core.Locale(sap.ca.scfld.md.app.Application.getImpl().getResourceBundle().sLocale);
        var formatter = sap.ca.ui.model.format.DateFormat.getDateInstance({style : "medium"},locale);
        return formatter.format(oValue);
      }

When render is completed, no value display on date picker.

fioricddev commented 8 years ago
Root cause:

cus.crm.opportunity.util.Formatter.dateFormatter(new Date()) in step 2 doesn't match with Dateformat of DatePicker. In result, DatePicker can not parse the input string date value. Such as: Jan 19, 2016.

Solution one:

Use DatePicker format method to format new Date() in step 2:


var oDatePickerStartDate = this.byId('datePickerStartDate'), 
    sTodayDateValue = oDatePickerStartDate._formatValue(new Date());

oDatePickerStartDate .setValue(sTodayDateValue); // sTodayDateValue: 19.01.2016
Solution two:
<DatePicker id="datePickerStartDate" displayFormat="medium" valueFormat="medium" ></DatePicker>
this.byId('datePickerStartDate').setValue(cus.crm.opportunity.util.Formatter.dateFormatter(new Date()));
// Configuration.js
var M_ABAP_DATE_FORMAT_PATTERN = {
        "" : {pattern: null},
        "1": {pattern: "dd.MM.yyyy"},
        "2": {pattern: "MM/dd/yyyy"},
        "3": {pattern: "MM-dd-yyyy"},
        "4": {pattern: "yyyy.MM.dd"},
        "5": {pattern: "yyyy/MM/dd"},
        "6": {pattern: "yyyy-MM-dd"},
        "7": {pattern: "Gyy.MM.dd", ignore:true},
        "8": {pattern: "Gyy/MM/dd", ignore:true},
        "9": {pattern: "Gyy-MM-dd", ignore:true},
        "A": {pattern: "yyyy/MM/dd"},
        "B": {pattern: "yyyy/MM/dd"},
        "C": {pattern: "yyyy/MM/dd", ignore:true}
    };

So you could choose 7, 8, 9 or C. Then input format cus.crm.opportunity.util.Formatter and DatePicker will use the default format pattern from locale json file to parse value. Such as: en.json with 'short' pattern:

dateFormat-long: "MMMM d, y"
dateFormat-medium: "MMM d, y"
dateFormat-short: "M/d/yy"

Otherwise, DatePicker will use the pattern from ABAP setting. Such as:

"1": {pattern: "dd.MM.yyyy"}

In this way, DatePicker default pattern value is: dd.MM.yyyy, but input value format in step 2 will use the different one in locale json file: "M/d/yy. In result, DatePicker can not parse input date value.