cancel
Showing results for 
Search instead for 
Did you mean: 

Add different form elements dynamically in MVC view

former_member198357
Participant
0 Kudos

Dear All,

I have created MVC view(XML) and I am using sap.ui.core.mvc.Controller.extend to define and initialize my controller. Now, I need to add form elements in my view dynamically with Odata binding based on value from backend system.

Could anybody please let me know how to do this.

Regards,

Bhavin

Accepted Solutions (0)

Answers (1)

Answers (1)

former_member9607
Active Participant
0 Kudos

Hi Bhavin,

If I am not misunderstood then you want to put dynamic controls of different type in your Form. Right?

You will have some properties to decide whether you should add Input or Dropdown.

For example,

The first element may be the Input and the second one will be Datepicker. This controls may change for some other record.

You can define your form in XML view and create an object of type FormContainer in controller ( onBeforeRendering method) . Add your elements of type FormElement in that container based on values retrieved from ODATA.

Assign that container to your Form in XML view.

Please let me know if you require more details on this or I am missing something.

Regards,

KK

former_member198357
Participant
0 Kudos

Hi KK,

Thanks for the reply.

I have already tried this option but I am getting very unusual error.

"Cannot read property 'Label' of undefined"

following is my code

          var formContainer = new sap.ui.layout.form.FormContainer()

                                   }),

                             

                    

               ]

               

          });

Could you please sahre some example if you already have with MVC controller

Regards,

Bhavin

former_member198357
Participant
0 Kudos

I was using SAP.UI.COMMONS.<Elements> instead of SAP.M.<ELEMENTS>. Now its working fine.

sandeep_mekala
Explorer
0 Kudos

Hi

I have a similar requirement in my PoC. I need to add controls dynamically from controller to view base on some data. Is there way to do this using mobile controls.(sap.m.<element>).

One of the approach that I think of is have different fragments for each control and dynamically push this fragments to view based on data.

Thanks in advance:)

Former Member