0
votes

In my process we have a deadline which is a date. But this date is not set until a certain state has been reached. Say i want to display this date before it has been set and it is still initial.

The date is returned as a string and thus 00000000 in my model. (I understand that strings are not dates, but this was choosen and i have to go with it.)

Here is the control:

<DatePicker type="Date" placeholder="{i18n>DateStateUnknown}"
     enabled="{
        parts : [ 
            {path : 'settings>/incidentLock/MayChangeResponsible'},
            {path : 'DeadlineDate'} 
        ], formatter: 'com.company.inc.util.Formatter.mayChangeDeadline' }"
    displayFormat="long"
    value="{path:'DeadlineDate', 
            type: 'sap.ui.model.type.String', 
            constraints: { minLength : 2}, 
            formatter: 'com.company.inc.util.Formatter.setBaseDate'}"
    valueFormat="yyyyMMdd" />

My formatter looks like this:

setBaseDate: function(val){
   try{
    if(val=="00000000"){
                    return "";
                }else{
                    return val;
                }
            }catch(e){
                return "";
            }
        },

The diplay works as a expected. Nothing is displayed when the date is empty. The only thing is that with this formatter I loose my connection to the odata model. This means that whenever I make a change to the value, it does not reflect in the odata model and thus I cannot save this date. The same holds true when I set a value for the first time, when the control is still empty.

Does anybody know how to fix this? I'd rather not look at other options as hiding the field.

1
might the comparison val=="00000000" be wrong? Is it really a string containing 0000000 or might it be a number? find it out via console.log("correct") before returning the value ..dotchuZ

1 Answers

0
votes

The only way to solve your issue is to

  1. get rid of the formatter, and
  2. have an empty date be null or an empty string, but anything other than "00000000"

Reason being, using a formatter makes your control readonly, according to the API:

Currently, calculated fields work only from model to view, read only, and the values can be accessed via a formatter function.

Furthermore, a date of "00000000" with format yyyyMMdd rightfully resolves to December 1, 1969, so if you want to avoid that, the date value should be something different than "00000000"