cancel
Showing results for 
Search instead for 
Did you mean: 

same Fragment Multiple times in view ?

Former Member
0 Kudos

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.

Accepted Solutions (0)

Answers (4)

Answers (4)

junwu
Active Contributor
0 Kudos

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

avoid js view if possible

Former Member
0 Kudos

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.

sagarikagattu
Participant
0 Kudos

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);

}

former_member233511
Participant
0 Kudos

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);
}
former_member186852
Contributor
0 Kudos

Hi Efim ,

I have added Fragment multiple time in the view ( let say 4 times ) now i want to delete one fragment out of that 4. How can i do that ?

Thanks in advance.

Regards,

Meghal Shah

former_member233511
Participant
0 Kudos
var vItem = 1 // can be index, id, or directly item (form)
oContainer.removeItem(vItem);