padibro
padibro

Reputation: 1382

How I can set the value of element of a fragment?

This is my fragment, The fragment not have a controller

<core:FragmentDefinition
  xmlns="sap.m"
  xmlns:core="sap.ui.core">
  <Dialog
    title="Invio report via mail">
    <content>

        <FlexBox
            alignItems="Start"
            justifyContent="Center">
            <items>
             <TextArea id="idMailReport" value="themail.mail.it" rows="1" cols="50" /> 
            </items>
        </FlexBox>



    </content>
    <beginButton>
      <Button text="Ok" press="onDialogOkButton" />
    </beginButton>
    <endButton>
      <Button text="Close" press="onDialogCloseButton" />
    </endButton>
  </Dialog>


</core:FragmentDefinition>

Ho I can set che value of TextArea element?

I try to set it from a controller where I call the fragment:

var dialogFrafment = sap.ui.xmlfragment(
                "dialogFragment",
                "appIntra.fragment.dialog",
                this // associate controller with the fragment
          );
          this.getView().addDependent(dialogFrafment);
          dialogFrafment.open();
          this.byId("idMailReport").setValue("initial.mail.com");

Can you help me?

Upvotes: 1

Views: 22125

Answers (3)

empe3.X
empe3.X

Reputation: 21

A bit outdated, but might be useful for others. When you reuse your fragment inside a view, giving it unique id like:

    var dialogFrafment = sap.ui.xmlfragment(
            "dialogFragment", // this is fragment's ID
            "appIntra.fragment.dialog",
            ...
      );

retrieving id of your nested control goes like:

this.byId(sap.ui.getCore().Fragment().createId("dialogFragment", "idMailReport"));

That way, your prepend fragment's id to your control's id.

Upvotes: 1

Haojie
Haojie

Reputation: 5713

please try

sap.ui.getCore().byId("idMailReport").setValue("initial.mail.com");

it should work.

Here is the official document.

Upvotes: 6

padibro
padibro

Reputation: 1382

I solve it!

var dialogFrafment = sap.ui.xmlfragment(
                "appIntra.fragment.dialog",
                this.getView().getController() // associate controller with the fragment            
          );

my problem is that i had set a name of a fragment: "dialogFragment" Whitout it all work! ;)

Upvotes: 2

Related Questions