PDA

View Full Version : "Combo with Templates and Ajax" and xtype



Natal'ia
14 Nov 2012, 2:54 AM
Hi!
I've used an exemple http://dev.sencha.com/deploy/ext-4.1.0-gpl/examples/form/forum-search.html.
And it works (see code)



Ext.namespace("Ext.app.com");


Ext.app.com.Search = Ext.extend(Ext.form.ComboBox, {
initComponent: function(){
Ext.apply(this, {
store: ds,
minChars: 1,//The number of charcters before autocomplete and typeAhead activate (defaults to 4)
displayField:'name',
typeAhead: false,
loadingText: 'Searching...',
width: 570,
pageSize:10,
hideTrigger:true,
applyTo: 'search',
tpl: resultTpl,//The name of element in html-file
itemSelector: 'div.search-item'//The name of my template (see up)
})


Ext.app.com.Search.superclass.initComponent.apply(this, arguments);
}
});


Ext.reg("searchCB", Ext.app.com.Search);

var search = new Ext.app.com.Search({
renderTo: bd
});


<input type="text" size="40" name="search" id="search" />

But if I write as xtype it doesn't work. (see code)


var gridForm2 = new Ext.FormPanel({ id: 'goods-form2',
frame: true,
labelAlign: 'left',


bodyStyle:'padding:15px',
width: 750,
layout: 'absolute', // Specifies that the items will now be arranged in columns
items: [
{
items: {
xtype: 'searchCB',
name: 'search1',
fieldLabel: 'search1'
}
},{
buttons: [{
//text: '+',
width : 24,
height: 24,
icon: 'js/icons/add.gif',
style: {
padding: '1px'
}
}]
}
],
renderTo: bd
});

What's wrong?
Thanks.

willigogs
14 Nov 2012, 6:03 AM
Why do you have items within items in your formpanel?

Unless specified otherwise, the default item within a formpanel will be a textField - therefore you seem to be attempting to make your combo the child item of a textField (and textFields do not support having items).

You also have buttons within your items, which again is not correct.

I'm assuming your code should really be like the following:


var gridForm2 = new Ext.FormPanel({
id: 'goods-form2',
frame:true,
bodyStyle:'padding:15px',
width: 750,
renderTo: bd,
layout:'form',
defaultType: 'textfield',
items: [{
xtype: 'searchCB',
name: 'search1',
fieldLabel: 'search1'
}],
buttons: [{
//text: '+',
width : 24,
height: 24,
icon: 'js/icons/add.gif',
style: {
padding: '1px'
},
handler: function() {
alert('Click')
}
}]
});

Natal'ia
14 Nov 2012, 7:02 AM
Many thanks, willigogs.
You're right.