cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

SAPUI5 formatter function not working properly inside Input Control

MKM
Active Participant
0 Likes
3,207

Hi Experts,

I need to highlight a few of the table's cell border colors on the basis of a condition and pre-fill it with some negative value.

View.xml

<t:Column width="100px">
    <Label text="ActualQty"/>
    <t:template>
       <Input id="idInput" value="{ parts: [ {path: 'viewData>ACT_QTY'}, {path: 'viewData>MTART'} ], formatter: '._formatter.defaultInput' }">
            <customData>
                <core:CustomData key="colorclass" value="{path: 'viewData>MTART', formatter: '._formatter.formatCell'}" writeToDom="true"/>
            </customData>
       </Input>
    </t:template>
</t:Column>

Formatter.js

 formatCell: function (iValue) {
        try {
            iValue.toString();
        } catch (err) {
            iValue = "foo";
        }
        return iValue.toString();
    },

    defaultInput: function (iValue, iValue1) {

        if (iValue !== 0 && iValue1 === "HALB") {
            iValue = "-1";
            return iValue;
        } else {
            return iValue;
        }
    }

style.css

  div[data-colorclass="HALB"] { 
      border: 4px solid #fdf6b1 !important;
    }

Highlighting and the default value is appearing. But inside the controller, The input value is not coming.

if I remove parts and pass single input param to formatter function, its working. But I need both the values to built my logic.

Accepted Solutions (0)

Answers (2)

Answers (2)

MKM
Active Participant
0 Likes

Now I understood, the formatter function will make it one-way binding. The link has a solution using custom type to make it two-way binding. But I am not able to create the Type for my case. Please guide.

junwu
SAP Champion
SAP Champion
0 Likes

once you use formatter, it is oneway binding, means model--->UI, your input change in ui won't come to model.

MKM
Active Participant
0 Likes

Any alternative to get the value in the controller function ?