Skip to Content
author's profile photo Former Member
Former Member

How to pass context of oController into the formatter function?

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

Add a comment
10|10000 characters needed characters exceeded

Assigned Tags

Related questions

2 Answers

  • Best Answer
    author's profile photo Former Member
    Former Member
    Posted on Jan 14, 2015 at 10:23 AM


    Hi Murthy,

    Have you tried this.

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

    value: "",

    formatter: [oController.formatPayOutAmount ,oController]

    });

    Thank you.

    Regards,

    Pruthvi.

    Add a comment
    10|10000 characters needed characters exceeded

    • Former Member Former Member

      Hi Pruthvi,

      Althoug the question is answered, could you please extend your answer to cover below point.

      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

  • Posted on Jan 14, 2015 at 10:13 AM

    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

    Add a comment
    10|10000 characters needed characters exceeded

    • 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

Before answering

You should only submit an answer when you are proposing a solution to the poster's problem. If you want the poster to clarify the question or provide more information, please leave a comment instead, requesting additional details. When answering, please include specifics, such as step-by-step instructions, context for the solution, and links to useful resources. Also, please make sure that you answer complies with our Rules of Engagement.
You must be Logged in to submit an answer.

Up to 10 attachments (including images) can be used with a maximum of 1.0 MB each and 10.5 MB total.