cancel
Showing results for 
Search instead for 
Did you mean: 

Way to access view parameter in controller- sap ui5

former_member338801
Participant
0 Kudos

Hi Experts,

I am not able to access view parameter in the custom function in the view controller.

I tried this.getview.byid.getvalue / sap.ui.getcire.byid.getvalue but always getting error.

Can you please help and suggest?

Thanks and regards

RK

Accepted Solutions (1)

Accepted Solutions (1)

junwu
Active Contributor
0 Kudos

you have to define the event handler like this if you are doing it in controller,

liveChange: [this.handleLiveUpdateAsset,this]

Answers (3)

Answers (3)

arthursilva
Active Participant
0 Kudos

Hello ram,

The problem is that the View and the sap.m.Input are not sharing the same context. In other words, both Input field and controller are sharing the same scope, but liveChange does not. That's why you're receiving message "this.getView() is not method and getValue()", the Input field handler is out of the scope.

To make them visible, at the same scope, try to bind the input field with the view while its creation, like this:

  var oInput = new sap.m.Input({
    type: sap.m.InputType.Text,
    id:"serial"+i,
    value:(srNumArr[i])?srNumArr[i]:"",
    enabled:(srNumArr[i])?false:true,
    liveChange: this.handleLiveUpdateAsset,     layoutData: new sap.ui.layout.GridData({span: "L10 M10 S9"}), placeholder: "Serial Number"})
}).bind(this);

BR
Arthur Silva

former_member338801
Participant
0 Kudos

Thanks Shiva for helping me.

It didn't work.

rrastogi
Member
0 Kudos

Where are you calling this custom function?

Also could you please share the error or debug message on console?

former_member338801
Participant
0 Kudos

for(var i=0;i<qtyReceive;i++){ //var n = i;

var oInput = new sap.m.Input({

type: sap.m.InputType.Text,

id:"serial"+i,

value:(srNumArr[i])?srNumArr[i]:"",

enabled:(srNumArr[i])?false:true,

liveChange: this.handleLiveUpdateAsset, layoutData: new sap.ui.layout.GridData({span: "L10 M10 S9"}), placeholder: "Serial Number" });

Upon calling

this.getView().byId('IND').getValue();

It shows this.getView() is not method and getValue() is not defined. It looks like it not able to access this ind parameter. Any help will be appreciated.

Thanks

junwu
Active Contributor
0 Kudos

code please....

former_member338801
Participant
0 Kudos
  1. Controller.js changes :

handleLiveUpdateAsset: function(oEvent){

var indicator= this.getView().byId('IND').getValue();

if(indicator !== 'x'){

var itag = oEvent.getParameter("id").substr(6);

var value = oEvent.getParameter("value");

var id = 'asset'+itag;

sap.ui.getCore().byId(id).setValue(value);

}

},

  1. Add below field to view :

<Input id="IND" width="0.5%" value="{IND}" visible="false"/

Please check thr code and suggest.

Regards,

RK