Skip to Content
0

same Fragment Multiple times in view ?

Feb 06 at 01:46 PM

43

avatar image
Former Member

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)
10 |10000 characters needed characters left characters exceeded
* Please Login or Register to Answer, Follow or Comment.

4 Answers

Efim Parshin Feb 06 at 02:32 PM
0

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);
}
Show 2 Share
10 |10000 characters needed characters left characters exceeded

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

0
var vItem = 1 // can be index, id, or directly item (form)
oContainer.removeItem(vItem);
0
Sagarika Gattu Feb 07 at 07:14 AM
0

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

}

Share
10 |10000 characters needed characters left characters exceeded
avatar image
Former Member Feb 07 at 10:57 AM
0

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.


Share
10 |10000 characters needed characters left characters exceeded
Jun Wu Feb 07 at 02:32 PM
0

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

avoid js view if possible

Share
10 |10000 characters needed characters left characters exceeded