cancel
Showing results for 
Search instead for 
Did you mean: 

Function parameter value from view js file is not getting invoked in controller function

VenkyM
Participant
0 Kudos

Hi ,

I am trying to create form in SAPUI5 using sap.ui.layout.form.Form and am trying to reuse the code for generating same textfield many times. In order to do that I placed the code in a function in controller js file and When I am trying to pass a value from function in view js file to function in controller js file , it is not getting passed properly ie function is getting called but not the values.

Below is the code ,

//function in the controller js file

textField: function (labeltext,placeholder){

  var formElement = new sap.ui.layout.form.FormElement({

  label : new sap.ui.commons.Label({

text : this.labeltext    // passed text from view js is not getting here

  }),

  fields : [ new sap.ui.commons.TextField({

  required : true,

  layoutData : new sap.ui.layout.form.GridElementData({

  hCells : "3"

  }),

  placeholder : this.placeholder   // passed text from view js is not getting here

  }) ]

  });

  return formElement;

  }

// function in the view js file

  createContent : function(oController) {

  var oLayout2 = new sap.ui.layout.form.GridLayout("L2");

  var oForm2 = new sap.ui.layout.form.Form("F2", {

  title : new sap.ui.core.Title({

  text : "Employee Registration Form",

  tooltip : "Register here"

  }),

  editable : true,

  layout : oLayout2,

  formContainers : [ new sap.ui.layout.form.FormContainer("C2", {

  formElements : [

        

  oController.textField("Employee Name","Please enter ur name"), // calling function textField here

  ]

  }) ]

  });

  oForm2.placeAt("content");

  }

output :

Please guide me in this.

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

Hi Venkatesh,

did you try without putting "this." before the variable?

Regards,

Georgi

VenkyM
Participant
0 Kudos

Hi Georgie,

Thanks for quick reply,I tried without "this" and it got resolved.

Former Member
0 Kudos

No Problem.

As a correct answer should be marked my post, not yours

Regards,

Georgi

Answers (1)

Answers (1)

saivellanki
Active Contributor
0 Kudos

Hi Venkatesh,


Why are you passing the value as this.labeltext? it should be normal labeltext, same thing for place holder.


Try -



textField: function (labeltext,placeholder){

  var formElement = new sap.ui.layout.form.FormElement({

  label : new sap.ui.commons.Label({

text : labeltext    // passed text from view js is not getting here

  }),

  fields : [ new sap.ui.commons.TextField({

  required : true,

  layoutData : new sap.ui.layout.form.GridElementData({

  hCells : "3"

  }),

  placeholder : placeholder   // passed text from view js is not getting here

  }) ]

  });

  return formElement;

  }

Regards,

Sai Vellanki.