-2

Below is the code snippet of the view in XML, I am able to read the id "Name1" but unable to read/write "Name2" that's in an HTML tag, it returns undefined. Can you help me with how to access the "Name2" that in the HTML tag?

Thanks

sap.ui.getCore().byId("Name1").setValue(oData.FirstName + " " + oData.LastName + ); // sets the value

// Retunrs undefined
sap.ui.getCore().byId("Name2").setValue(oData.FirstName + " " + oData.LastName + ); // Sets no value
<core:FragmentDefinition
  xmlns:core="sap.ui.core" xmlns:mvc="sap.ui.core.mvc"
  xmlns:l="sap.ui.layout" xmlns:f="sap.ui.layout.form" xmlns="sap.m"
  xmlns:html="http://www.w3.org/1999/xhtml">
  <Panel class="pnlSearchDate" id="pnlContent">
    <html:span class="textcolor">
      <html:b>TITLE</html:b>
    </html:span>
    <html:br />
    <HBox alignItems="Center">
      <Label class="textcolor" width="300px" text="{i18n>txtName}" />
      <Input id="Name1" class="inputbordercolor" editable="false" width="300px"/>
    </HBox>
    <HBox justifyContent="Center">
      <VBox width="100%">
        <html:div class="textcolor"
          style="font-size: 0.875rem;font-family: Arial,Helvetica,sans-serif;line-height:25px;color:#6a7694;text-align:justify;">
          <html:p>
            I,
            <html:input class="inputEntry" id="Name2" 
              editable="false"></html:input>
            I hereby confirm that I received one session of XXX.
          </html:p>
        </html:div>
      </VBox>
    </HBox>
  </Panel>
</core:FragmentDefinition>
Sandra Rossi
  • 11,934
  • 5
  • 22
  • 48
Zayidu A
  • 13
  • 2
  • 7
  • Does this answer your question? [How to Access Elements from XML Fragment by ID](https://stackoverflow.com/questions/39660161/how-to-access-elements-from-xml-fragment-by-id) – Boghyon Hoffmann Feb 03 '20 at 11:20

2 Answers2

0

Since I want to access the HTML Div ID, I simply used the below code to set the value and it works:

document.getElementById("Name2").value = _fullName;
Zayidu A
  • 13
  • 2
  • 7
  • Check this: https://stackoverflow.com/questions/39660161/how-to-access-elements-from-xml-fragment-by-id/47872515#47872515 – Zayidu A Feb 04 '20 at 13:57
-1

Try the below solution:

sap.ui.getCore().byId(this.getView().createId("Name2"));

Source: https://stackoverflow.com/a/37171149/9262488

NiK648
  • 1,484
  • 1
  • 9
  • 18
  • Unfortunately, this won't work since `byId`-methods retrieve only live UI5 controls. At the same time, the solution from the linked source can't solve the problem either since the HTML element is defined within the fragment. Accessing such elements [depends on how the fragment was created](https://stackoverflow.com/a/47872515/5846045). – Boghyon Hoffmann Feb 03 '20 at 10:16