on 06-17-2015 10:43 AM
Hi
I have used one Datepicker in the view, initially i have set some date value to Date picker.
On change of Date, change function() will trigger, in that function i need to compare old Date and new date. So is there any way to get old Date value from Datepicker.
Thanks and Regards
Nandish
Create 1 global variable and save your initial date in that.
through out your controller you will get that date so using that compare with your new date.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Datepicker is in Table column, for first time data is coming from backend, we are binding data to the table. So through json model , while changing date method is triggering i Need old value since i have more than 10 records so I cant save date of every records in a separate varible.
Is there any way to fetch date value from method only.
Ex:-
For first let Date be 21/03/2014 I changed 25/03/2014
Next time I changed 25/03/2014 to 27/03/2014.
How I can get old values i.e 25/03/2014
Please, please, please! Do not use global variables... Why are global variables considered bad practice? (Javascript) - Stack Overflow
Better use a temporary JSONModel which holds your initial values. It makes comparing also a LOT easier between models
i'm declaring a variable in global and store in a model. using that model reference i'm doing binding in my view. is this bad??
var headerModel = {};
sap.ui.controller("sfs", {
onInit: function() {
var oModel = new sap.ui.model.json.JSONModel(headerModel);
this.getView().setModel(oModel, "HeaderModel");
},
})
Yes, global variables are bad
I would not use global variables if you can avoid it.
In your case, why not have a model (or model node) with your initial values and a separate model (or model node) with the new/changed values?
Therefor you don't need any global variables, you can just copy the initial model property to the corresponding second model property.
You can even reset your screen's control to the initial state ('reset button' functionality) by copying the initial model to the second model if you want.
simple example,
like above in init() i'm initialize the model then,
in view.xml, i'm bind like below.
<Input id="AmountId" value="{HeaderModel>/Amount}" />
so what ever in this Amount input field that is available in my controller,
for example,
any method in controller,
var headerModel = {};
sap.ui.controller("sfs", {
onInit: function() {
var oModel = new sap.ui.model.json.JSONModel(headerModel);
this.getView().setModel(oModel, "HeaderModel");
},
onReview: function() {
alert(headerModel.Amount); //For validation purpose
},
onSave: function() {
alert(headerModel.Amount); //For Posting purpose
},
})
Like this through out the controller i can get. so any easy way is there to do like this?
Well, for starters, I would not load the model in the onInit since it will be loaded only once
No, what I mean is the following:
Now, let's say you want have changed a values in a 'mydatevalue' field in a certain row in a table, and you want to compare it with the old value, you just simply compare the initial model's property to the table model:
doReview : function(oEvent) {
var oModel = this.getView().getModel("main");
var oModelInitial = this.getView().getModel("initial");
var sPath = oEvent.getSource().getBindingContext("main").getPath() + "/mydatevalue";
sap.m.MessageBox.show(
"Old date: " + oModelInitial.getProperty(sPath) +
", new date: " + oModel.getProperty(sPath)
)
}
Robin van het Hof thank you somuch for clarifying my doubts.
User | Count |
---|---|
88 | |
10 | |
10 | |
9 | |
6 | |
6 | |
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.