on 11-02-2015 11:03 AM
Hi ,
I've created new control via extend and I want to know where should I put the text:... and layoutData
Here how its done in regular way
var oTitle = new sap.ui.core.Title({ text: "{i18n>title_test}", layoutData: new sap.ui.layout.GridData({ span: "L12 M12 S12" }) }); | |||||
I've composite control which I use the title like following and I need to applay both the layout and text
extend....
metadata: { | ||||
aggregations: { | ||||
title: { | ||||
type: "sap.ui.core.Title", | ||||
multiple: false | ||||
}, |
Hey Joerg Ben
Adding that title as a public aggregation to your control means that any user using your control can go ahead and add any entire sap.ui.core.Title with or without specified layout data. So if your control's name is MyCustomControl and they want to specify a title for it, they will do the following:
var customControl = new MyCustomControl();
customControl.setAggregation('title',
{
new sap.ui.core.Title({text: "{i18n>title_test}"});
})
If you want the title element to specifically have that layoutData and just want a user to specify the text part it might be better to make that aggregation private and do the following in your init function of your custom control :
this.setAggregation('_title',
{
new sap.ui.core.Title(
{
layoutData: new sap.ui.layout.GridData(
{
span: "L12 M12 S12"
})
});
})
In your metadata specify a new property:
metadata:
{
properties:
{
"titleText" : {type : "string", defaultValue: "Title"}
}
}
Then a user can do the followiing:
var customControl = new MyCustomControl();
customControl.setTitleText("I want this Title");
In your control just remember to set the specified text now in the titleText property to your Title aggregate.
This can be done in the render function of your control:
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
HI Riekert ,
This is what I need but somehow when I use
renderer: function(oRm, oControl) {
oRm.write('><div>'); | ||
oRm.renderControl(oControl.getAggregation("_title")); |
I got error Unhandled Error: C.getVisible is not a function
and I dont have it on my code, any idea?
Do you have some JSBIN or plunker for this which I can use as reference ?
this is the code which I use in the control
aggregations: { | ||||
_title: { | ||||
type: "sap.ui.core.Title", | ||||
multiple: false, | ||||
visibility: "hidden" | ||||
}, |
And in init I use
init: function() { | ||||
this.setAggregation("_title", new Title({ | ||||
text:"test", | ||||
layoutData: new sap.ui.layout.GridData({ | ||||
span: "L12 M12 S12" | ||||
}) | ||||
})); |
Thanks in advance!
Joerg
getVisible is a method in a supercalss of all controls
seems like you dont extend it (or dont extend it properly) post the code of your custom control
Hi Maksim
return oControl.extend("myCompositeControl", {
metadata: {
aggregations: {
_title: {
type: "sap.ui.core.Title",
multiple: false,
visibility: "hidden"
},
This is the init
init: function() {
this.setAggregation("_title", new Title({
text:"test",
layoutData: new sap.ui.layout.GridData({
span: "L12 M12 S12"
})
}));
This is the renderer
renderer: function(oRm, oControl) {
oRm.write('<div');
oRm.writeControlData(oControl);
oRm.writeClasses();
oRm.write('><div>');
oRm.renderControl(oControl.getAggregation("_title"));
The debugger is failed on the line
oRm.renderControl(oControl.getAggregation("_title"));
Any idea?
Thanks!
Joerg
This is part of the signature accoutering to the following
This issue is happen on title and not on label...
so i assume it is
sap.ui.define([
"sap/ui/core/Control"
], function (Control) {
"use strict";
return Control.extend("myCompositeControl", {
metadata: {
aggregations: {
_title: {
type: "sap.ui.core.Title",
multiple: false,
visibility: "hidden"
},
and you use it like
var newcntrl = new myCompositeControl();
??
Hey
You are getting that error because the Rm.renderControl only renders Controls. Title is an element. Sorry about that. Try the following:
sap.ui.core.Title.extend("myCustomTitleElement",
{
init:function()
{
this.setLayoutData(new sap.ui.layout.GridData(
{
span: "L12 M12 S12"
}));
}
});
Then you use it as followed:
var title = new myCustomTitleElement({text: "My custom title"});
That which is returned from new myCustomTitleElement() is still an element not a control. So you should be able to use it exactly the way one would use an the original sap.ui.core.Title.
Hey Joerg Ben
I had a look in the ui5 git files how they render elements in controls. sap.ui.unified.Menu is a control that has an Element array of MenuItems as aggregates. the Control Menu renders a menuItem (element) by first checking if the menuItem has a render function. If menuItem.render returns undefined, the render function is not available. After checking if the function exists the funtion is called and the control's oRm is sent in as a parameter.
In that function oRm.write is called to render html code.
sap.ui.core.Title does not have a render function. Thus you can either extend it and write your own prototype.render function or just render it in the control using oRm.write.
Have a look at a control with layoutData to see what classes and such are added. Then you could manually add it.
I looked at the following files on git:
openui5/Menu.js at master · SAP/openui5 · GitHub
I do not see that you need to reapply the text and layout. Maybe you can shed some lights on what you wish to do.
-D
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
HI Dennis,
Lets say that I've simpleForm with the following control
var oTitle = new sap.ui.core.Title({
text: "{i18n>title_test}",
layoutData: new sap.ui.layout.GridData({
span: "L12 M12 S12"
})
});
Now I want to put this control as part as other controls in new composite control,
and I want internally (in the extend) put this text and layoutData, how should I do that ?
Thanks in advance!
Joerg
HI All,
Any Idea how to achieve them?
Thanks!
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
76 | |
9 | |
8 | |
7 | |
6 | |
5 | |
5 | |
5 | |
5 | |
5 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.