cancel
Showing results for 
Search instead for 
Did you mean: 

Uncaught Error: Error: adding element with duplicate id 'menuBarID'

former_member197578
Participant
0 Kudos

Hello experts,

I cannot figure out why am i getting following error:

uncaught Error: Error: adding element with duplicate id 'menuBarID'

ID has been used just once in the application, so what can be the reason behind this error??

Please help.

Thank you,

Best Regards,

Chetna

Accepted Solutions (1)

Accepted Solutions (1)

Private_Member_15166
Active Contributor
0 Kudos

Hi,

You will be clicking or calling an event or function module where ID would be created again and again.

Don't give IdName, Sapui5 will automatically assign a valid id name.

or use like this.

I have written this in view.

              var oInput = new sap.ui.commons.TextField(this.createId("nameId"),{

                           value: "Dhananjay Choubey"

              });


and for accessing that element, I have written this in controller.


              var json = {};

              json.name = sap.ui.getCore().byId(this.createId("nameId")).getValue();


This is just a refrence. Use according to your code.

Regards

Dhananjay

Former Member
0 Kudos

Hi Dhananjay,

I am not able to retrieve the TextField value in controller when i use this.createId("nameId").

Please let me know if i am missing something.

my code

var oInput = new sap.ui.commons.Textfield(this.createId("nameId"));

In controller

var oInput = sap.ui.getCore().byId(this.createId("nameId")).getValue();

Thanks and Regards,

Saravanan

Private_Member_15166
Active Contributor
0 Kudos

I have used like this.

IN View      

createContent : function(oController) {

              var oText = new sap.ui.commons.TextView({

                     text: "Enter your name:"

              });

             

              var oInput = new sap.ui.commons.TextField(this.createId("nameId"),{

                           value: "Dhananjay Choubey"

              });

             

              var oButton = new sap.ui.commons.Button({

                     text: "Submit",

                     press: function(){

                           oController.navigateToView2("view2");

                     }

              });

             

              var ele = [ oText, oInput, oButton ];

             

              return ele;

       }

In Controller

       navigateToView2: function(view){

             

              var json = {};

              json.name = sap.ui.getCore().byId(this.createId("nameId")).getValue();

             

              this.myModel.setData(json);

              sap.ui.getCore().setModel(this.myModel);

             

              var oRouter = sap.ui.core.routing.Router.getRouter("appRouter");

              oHashChanger = sap.ui.core.routing.HashChanger.getInstance();

              oHashChanger.setHash(oRouter.getURL(view));

       }


And it's working.


See where you are making mistakes.

This message was moderated.

Answers (5)

Answers (5)

kkoopman
Explorer
0 Kudos

To solve: Uncaught Error: Error: adding element with duplicate id 'application-Test-url-component---Main'

when navigating back you have to remove "id": "Main" at "sap.ui5" in manifest.json at "sap.ui5":

"sap.ui5": {

"flexEnabled": false,

"rootView":

{

"viewName": "nl.something.example.view.Main",

"type": "XML",

"async": true,

"id": "Main"

}

0 Kudos

hi,

same issue i got this error while navigating back to my home page ! any help :

Uncaught Error: Error: adding element with duplicate id 'container-Services---View1'

karstenvoigt
Participant
0 Kudos

Hi,

could you solve that issue? I'm facing the same problem. I get an error: Error: adding element with duplicate id if I navigate around in a Launchpad application.

Thanks

Karsten

ChandraMahajan
Active Contributor
0 Kudos

Thread is now locked to prevent further necromancy.

Regards,

Chandra (Moderator)

Former Member
0 Kudos

Hi,

You are creating the id twice by using createId() thus to get the value write the below code.

sap.ui.getCore().byId("nameId").getValue();

Former Member
0 Kudos
ID has been used just once in the application, so what can be the reason behind this error??

Without seeing any code, i just can guess you're re-instantiating the same control again.