adding element with duplicate id

落爺英雄遲暮 提交于 2019-12-01 07:28:19

问题


I am creating a SAP Fiori application. I have input in a dialog box in that I have to fetch the input value. I am defining the dialog in fragment view.

When I try to give the id for input I am getting an error as adding element with duplicate id.

------ Fragment View------

<core:FragmentDefinition
  xmlns="sap.m"
  xmlns:core="sap.ui.core"
  xmlns:app="http://schemas.sap.com/sapui5/extension/sap.ui.core.CustomData/1">
  <Dialog title="Title"  class="sapUiPopupWithPadding" >
    <content>  
        <HBox> 
           <items> 
              <Text  text="Name"></Text> 
              <Input  value="" id="myId"  > </Input> 
           </items> 
       </HBox> 
    </content>
    <beginButton>
        <Button text="Ok"  press="DialogButton" />
    </beginButton>
</Dialog>

---Controller Code---

DialogButton:function(oEvent) {

   var myIdValue=sap.ui.getCore().byId("myId").getValue();

   console.log("ID Value :::"+  myIdValue);

   oDialogFragment.close();

}


回答1:


You create a new dialog fragment instance every time you need to open the dialog . This will cause the duplicated ID issue. Please keep a dialog fragment instance in your controller.

Please see the sample code:

DialogButton:function(oEvent) {
   if(!this.oDialog) {
      this.oDialog =  sap.ui.xmlfragment("you.dialog.id", this );
   }
   this.oDialog.open();
}



回答2:


take a look at the following help IDs in Declarative XML or HTML Fragments you need to add an ID when the fragment is instantiated, that way the control has a prefix which is unique



来源:https://stackoverflow.com/questions/25301081/adding-element-with-duplicate-id

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!