on 2020 Apr 06 1:02 PM
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);
}
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
73 | |
10 | |
9 | |
8 | |
8 | |
6 | |
6 | |
6 | |
5 | |
5 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.