Skip to Content
avatar image
Former Member

same Fragment Multiple times in view ?

repeatform.png

this is the method :New Entry Button

NewEntryPress1:function(oEvent){

this._reusableForm = new sap.ui.xmlfragment("sncr.notification.view.ReusableForm",this); this._reusableForm.placeAt('content');

}

but no content is coming on pressing new entry.

I want the another form under the form like the form displaying here ( given in fragment) .

This thing need multiple times, in every form have New Entry button.

repeatform.png (9.0 kB)
Add comment
10|10000 characters needed characters exceeded

  • Get RSS Feed

4 Answers

  • Feb 06 at 02:32 PM

    Hi! Why do you use "placeAt" method for adding entries? It' should be used once for bootstrapping application.

    You should use addAggregation method of your forms container to add new entry.

    For Example, your forms will be nested inside sap.m.VBox control, so then adding new form will be:

    NewEntryPress1:function(oEvent){
      if(!this._reusableForm) {
        this._reusableForm = new sap.ui.xmlfragment("sncr.notification.view.ReusableForm",this); 
      }
      var oContainer = this.byId('MyVBoxId');
      oContainer.addItem(this._reusableForm) //or oContainer.addAggregation('items', this._reusableForm);
    }
    
    Add comment
    10|10000 characters needed characters exceeded

  • Feb 07 at 07:14 AM

    Hello,

    If you have used a view can you check the below code once?

    onInit: function() {

    that = this;

    this._oView = this.getView();

    }

    NewEntryPress1:function(oEvent){

    this._reusableForm = sap.ui.xmlfragment("sncr.notification.view.ReusableForm",this);

    that._oView.addDependent(_reusableForm);

    }

    Add comment
    10|10000 characters needed characters exceeded

  • avatar image
    Former Member
    Feb 07 at 10:57 AM

    Hi Efim/Sagarika,

    I implemented both things, Efim suggested code i used and worked .But On click New entry button i got fragment content which also have New entry button with 'New Entry 2' as press method .

    But for button in form ( Fragment ) , even debugger is not going to Newentry2 method in controller.:

    NewEntryPress1:function(oEvent){ if(!this._reusableForm) { this._reusableForm = new sap.ui.xmlfragment("sncr.notification.view.ReusableForm",this); this.getView().byId(idfragment--new_entry); } var oContainer = sap.ui.getCore().byId('MyVBoxId'); oContainer.addItem(this._reusableForm) },

    NewEntryPress2:function(evt){

    if(!this._reusableForm) { this._reusableForm = new sap.ui.xmlfragment("sncr.notification.view.ReusableForm",this); }

    var oContainer = sap.ui.getCore().byId('MyVBoxId'); oContainer.addItem(this._reusableForm) },

    view.js:

    var btn_NewEntry= new sap.m.Button("btn_newentry",{ text: "NewEntry", press: oController.NewEntryPress1 });

    var vbox_Container= new sap.m.VBox("MyVBoxId",{}); this._reusableForm = new sap.ui.xmlfragment("","sncr.notification.view.ReusableForm",oController);

    return new sap.m.Page({ title: "SNCR Notification", content: [ label_InspectioLot,input_InspectioLot,btn_Execute,btn_NewEntry ,vbox_Container ] });

    fragment:

    <f:FormElement label="">

    <HBox xmlns="sap.m" visible="true" height="" width="" displayInline="false" direction="Row" fitContainer="false" renderType="Div" justifyContent="Center" alignItems="" >

    <items>

    <Button id="new_entry" text="New Entry" tooltip="New Entry" press="NewEntryPress2" visible="true">

    <layoutData> <FlexItemData growFactor="0.2" /> </layoutData>

    </Button>

    <Button id="" text="Save" tooltip="Save" press="onConfirmSave" visible="true">

    <layoutData> <FlexItemData growFactor="4" /> </layoutData> </Button>

    </items> </HBox> </f:FormElement>

    repeatform-buttonpress-issue.png . on click on highlighted button , i want same form again down to this as explained in NewEntry2 method.

    Add comment
    10|10000 characters needed characters exceeded

  • Feb 07 at 02:32 PM

    var btn_NewEntry= new sap.m.Button("btn_newentry",{ text: "NewEntry", press: [oController.NewEntryPress1,this] });

    avoid js view if possible

    Add comment
    10|10000 characters needed characters exceeded