cancel
Showing results for 
Search instead for 
Did you mean: 

Different DatePickers with same date format pattern

Former Member
0 Kudos

Hi I have an app which has multiple DatePickers across different views which have the same date format like this: "dd.MM.yyyy". I am implementing this as follows:


        // create model for date format

  var oDateModel = new sap.ui.model.json.JSONModel();

  oDateModel.setData({

  dateValue: new Date()

  });

  sap.ui.getCore().setModel(oDateModel, "et_dateFormat");

new sap.ui.commons.DatePicker("emphiredate-datePicker", {

  width: "150px",

  value: {

  path: "et_dateFormat>/dateValue",

  type: new sap.ui.model.type.Date({

  pattern: "dd.MM.yyyy",

  strictParsing: true

  })

  },

  })

Now. I have DatePicker which needs to just show the current date (for which above example works), then I have datepickers which will be set based on the id code of a person which means it should be empty when the form is first opened. If I use the same datemodel the the value is immediatelly set to current date.

Is it possible to use a custom date pattern and at the same time keep the datepicker empty on first open?

Thanks in advance

Accepted Solutions (1)

Accepted Solutions (1)

Qualiture
Active Contributor
0 Kudos

Not sure what you mean... if you specify a 'null' value, even with a specific date format, the date picker is empty on first use. See this example: Edit fiddle - JSFiddle

Former Member
0 Kudos

Thanks that helped me although i still have some weird anomalies...

One more question: I have to create a model for every datepicker i have, right? because otherwise if I set a date for one datepicker then all the other datepickers will be set to the same value?

santhu_gowdaz
Active Contributor
0 Kudos

why more models?? 1 model with different variable's.

like this,

  1. var oDateModel = new sap.ui.model.json.JSONModel(); 
  2.   oDateModel.setData({ 
  3. nullValue: null,
  4.   todayDate: new Date() ,

          etc,......

  });

and set the corresponding variable to the datepickers

Former Member
0 Kudos

thanks, didnt know i could do that:)

Former Member
0 Kudos

Can I add those variables to the model dynamically? Like addData or something?  It seems to me that setData will override my previous variables.

santhu_gowdaz
Active Contributor
0 Kudos

ya you can using "push" method you can add into the model. but for date i didn't tried like this.

Qualiture
Active Contributor
0 Kudos

using the model's setProperty method will do that for you

Former Member
0 Kudos

my json model looks like this:


var oDateModel = new sap.ui.model.json.JSONModel();

oDateModel.setData({

       emphiredate: new Date(),

       empborn: null,

       born: null,

       docreldate: null,

       docvalidto: null,

       drivinglicencefrom: null,

       payvalidfrom: new Date(),

       payvalidto: new Date("12.31.9999"),

       feevalidfrom: null,

       feevalidto: null,

       membvalidfrom: null,

       membvalidto: new Date("12.31.9999")

  });

sap.ui.getCore().setModel(oDateModel, "et_dateFormat");

Later i have a button which adds a new form element dynamically which is a datepicker and I set the value for it as follows:

sap.ui.getCore().getModel("et_dateFormat").setProperty(idOfNewElement, new Date()); // first i add try to add the new property

, new Date());


value: {

  path: "et_dateFormat>/" + idOfNewElement, // trying to access the newly added property

  type: new sap.ui.model.type.Date({

            pattern: "dd.MM.yyyy",

            strictParsing: true

          })

}

Unfortunatelly nothing happens. The datepickers format is correct but it should be displaying the current date which it actually is not.

Answers (1)

Answers (1)

santhu_gowdaz
Active Contributor
0 Kudos

Initially,

  1. var oDateModel = new sap.ui.model.json.JSONModel(); 
  2.   oDateModel.setData({ 
  3.   dateValue: null 
  4.   }); 
  5.   sap.ui.getCore().setModel(oDateModel, "et_dateFormat"); 


At the time to set today date,

sap.ui.getCore().getModel("et_dateFormat").setDateValue(new Date());

may be you need to refresh this model to fetch new data.