cancel
Showing results for 
Search instead for 
Did you mean: 

The given date instance isn't valid.

former_member338801
Participant
0 Kudos
767

Hi Experts ,

I am using DateRangeSelection control. How to handle null value in this case? I am getting this error in console when no value selected. It is creating problem during odata call it takes time to load the data.

Console Error : The given date instance isn't valid.

xml code :

<DateRangeSelection id="dateRange" displayFormat="MM-dd-yyyy" valueFormat="yyyyMMdd" change="handleChange" width="75%">
        <layoutData>
         <l:GridData span="XL3 L3"/>
        </layoutData>
       </DateRangeSelection>



Controller code :

 var aDate = that.getView().byId("dateRange").getDateValue();
   var adateFormatted = " ";
   var bdateFormatted = " ";
   if (aDate === " ") {
    adateFormatted = " ";   // currently just passing as blank value
   } else {
    var adateFormat = sap.ui.core.format.DateFormat.getDateInstance({
     pattern: "yyyMMdd"
    });
     adateFormatted = adateFormat.format(aDate);   // this same code is not working in case of blank value in the console it shows null
   }
   var bDate = that.getView().byId("dateRange").getSecondDateValue();
    if (bDate === " ") {
    bdateFormatted = " ";  // currently just passing as blank value

   } else {
    var bdateFormat = sap.ui.core.format.DateFormat.getDateInstance({
    pattern: "yyyMMdd"
   });
    bdateFormatted = bdateFormat.format(bDate);
   }
View Entire Topic
venkateswaran_k
Active Contributor
0 Kudos

Hi

Try this code in controller

handleChange: function (oEvent) {
  var sFrom = oEvent.getParameter("from"),
  sTo = oEvent.getParameter("to"),
  bValid = oEvent.getParameter("valid"),
  oEventSource = oEvent.getSource(),
  oText = this.byId("TextEvent");
  this._iEvent++;
  oText.setText("Id:" + oEventSource.getId() + "\nFrom: " + sFrom + "\nTo: " + sTo);
	if (bValid) {
    	oEventSource.setValueState(ValueState.None);
	} else {
		oEventSource.setValueState(ValueState.Error);
			}
		}

This will check for space