cancel
Showing results for 
Search instead for 
Did you mean: 

How to pass context of oController into the formatter function?

0 Kudos

Hello Friends,

I have a scenario where I have to pass the context of oController into the formatter function as inside the formatter function I want to access function belonging to oController. Below is code sample:

new sap.m.Input('payOut', {

  value: '',

  fomratter: oController.formatPayOutAmount 

})

Now inside fomatPayOutAmount() I want "this" to refer to oController.

Obvioulsy   [fomratter: oController.formatPayOutAmount , oController] is not working.

Regards,

Chidan

View Entire Topic
Qualiture
Active Contributor
0 Kudos

I'm not sure what you're after...

if your sap.m.Input control is instantiated in the view, and you have specified the formatter to call a method in your controller, then inside that method "this" refers to your controller.

Unless you're calling "this" from within an inner function, but without seeing your formatter function I cannot tell if that's the case

0 Kudos

Hi Robin,

Nopes I dont think it works as you said or I am getting something seriously wrong.

I have created an example below please have a look.

JS Bin - Collaborative JavaScript Debugging</title> <link rel="alternate" type=&q...

"this" will point the formatter function and not the oController.

Regards,

Chidan

Qualiture
Active Contributor
0 Kudos

You are absolutely right, I was too quick answering...

Pruthvi's answer is indeed the correct one

0 Kudos

Hi Robin,

Would you have an answer for this?

How to make sure formatter is called when the data is changed in the binded field. For now formatter is only called once during instantiation.

I tried to use model.refresh() and model.checkUpdate(), but model.refresh sets it to initail binded value and checkUpdate() is private method and if you see internally checkUpdate() also calls refresh()

Regards,

Chidan

Qualiture
Active Contributor
0 Kudos

Hi,

I'm not sure what you mean... if you update the model, then the formatter will just update accordingly

Check this little example http://jsbin.com/povoso/1/edit?html,js,output

Initially it shows an Input field with a value, and underneath it another Input field with a formatted value (based on the input of the field above)

If you now change the value in the first Input (and hit 'Tab' to update the model property), the second field will update just fine

0 Kudos

Hi Robin,

No this is not what I mean, lets say you have input field and in the formatter you append currency symbol like € or $ and send it back to the same input field.

Here the formatter is not called again when the input value changes.


Regards,

Chidan

Qualiture
Active Contributor
0 Kudos

If I understand you correctly, you want to manually change a value in an inputfield which also has a formatter assigned?

That is currently not possible. From the API docs:


Currently, calculated fields work only from model to view, read only, and the values can be accessed via a formatter function.

However, in theory you could create a new custom type which extends from SimpleType and have the formatter assigned there