on 07-23-2014 9:08 AM
Hi
I am using two sap.m.DateTimeInput controls for Begin and End Date of a trip. Now I want to calculate the duration of that trip based on the selected dates. The duration will be displayed on in a sap.m.Input.
Is there any possibility to start calculation and set the value in the input field after both dates have been selected by the user? Some kind of Listener?
Thank you very much
best regards,
Thomas Maier
Hi Thomas,
You could use a formatter function in the input field to calculate the duration:
var oDuration = new sap.m.Input({value:{
parts : ["/startDate", "/endDate"],
formatter : function(date1, date2) {
var days = (date2 - date1)/(1000*60*60*24);
return days;
}
}})
where startDate and endDate in this example are the properties bound to both datetimeinput controls
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi
Thank you for your help so far. Really appreciate that. Now I do the following:
this.oInputDuration.bindValue({
parts: [
this.oDateTimeInputBegin.getProperty("value"),
this.oDateTimeInputEnd.getProperty("value")
],
formatter: function(beginDate, endDate){
var duration = (endDate - beginDate)/(1000*60*60*24);
console.log(duration);
return duration;
}
});
oInputDuration in that case is the Input control. oDateTimeInputBegin and oDateTimeInputEnd are the two DateTimeInput controls.
Currently no error is thrown but the value of the Input control stays blank. Any idea?
best regards
Thomas Maier
Hi Thomas,
You can use data binding to display the calculated value in a text field.
Click on Testpage at the end of the page in the link below:
Documentation/AdvancedTopics/DataBinding/CalcFields – SAPUI5 Wiki (TIP CORE User Interface)
Read the event part on the link below:
You will know more on how an event if fired when a text in a field has changed.
Regards,
Ashvin
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Thomas,
Use the 'change' event: SAPUI5 SDK - Demo Kit
When one of the two is changed, I'd use javascript to calculate the difference.
Kind regards,
RW
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
90 | |
10 | |
10 | |
10 | |
7 | |
7 | |
6 | |
5 | |
4 | |
3 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.