PDA

View Full Version : form in a template



Severance
20 Sep 2010, 10:49 PM
Hello all !!

I have a simple question : how to add a form in a template ?

So I have this code working well :

var infos = new Ext.Component({
title: 'Infos',
cls: 'infos',
iconCls: 'user',
scroll: 'vertical',
tpl: [
'<tpl for=".">',
'<p>Utilisateur : '+utilisateur.loginUtilisateur+'</p>',
'</tpl>'
]
});

I want to add a form button in the tpl.

How can I do that ?

thanks !

Severance
22 Sep 2010, 10:20 PM
up, I think it is not so hard, is it ?

evant
22 Sep 2010, 11:02 PM
No, it's currently not supported to use forms in templates. Why would you want to do that though? Just put the form as a child item of the container.

Severance
11 Nov 2010, 12:58 AM
could you give me an example of a child ?

JRS
23 May 2012, 5:32 AM
Was a solution found for this?

mrduck
29 Oct 2012, 8:30 AM
No, it's currently not supported to use forms in templates. Why would you want to do that though? Just put the form as a child item of the container.

I'd like to have a dynamic amount of fields, dynamic field names and want to put two textfields next to each other.
That's why it would be easy to use Xtemplates in form pages.

Is there any solution currently in ST1.1

gmz
30 Oct 2012, 11:40 PM
I've done something like this. I don't have any simple example, but will describe how it worked:
I have an empty component (Panel), and dynamically add children in a loop. In my case children are form-panel's, so I can load data from some Store or from Ajax call.

Something like this:


//parent class:
App.views.XParent = Ext.extend(Ext.Panel, {
id: 'xParent',
layout: 'auto',
scroll: 'vertical',
items: [
],
});
Ext.reg('xParent', App.views.XParent);

//children class:
App.views.XChild = Ext.extend(Ext.form.FormPanel, {
items:[{
xtype: 'fieldset',
items: [
//define fields here
]
}]
});
Ext.reg('xChild', App.views.xChildren);

//Function creating children.
createChildren: function(data){
var parent = Ext.getCmp('xParent');

parent.removeAll();
for(var i=0; i<data.length; ++i){
//create component
var newCmp = Ext.create({
xtype: 'xChild',
id: ('xChild_'+i) //optional
});

//load data to form fields
newCmp.load(data[i]);

newCmp.items.getComponent(0).setTitle('Item nr. '+(i+1));

parent.add(cmp);
}

parent.doLayout();
}

SunilRao
18 Jan 2013, 1:40 AM
Hey Hi,
I'm new to Sencha
Can you show me how to use setValues() in form.
Please!