PDA

View Full Version : ComboBox - when i insert it twice, it losts its Store



ytppa
15 Dec 2011, 1:04 AM
I declare my ComboBox:

var s_f_uch = new Ext.form.ComboBox({
xtype: 'combo',
allowBlank: false,
editable: false,
triggerAction: 'all',
typeAhead: false,
width:180,
store: [ ['1',item1], ['2','item2'], ['3','item3'] ],
fieldLabel: 'label',
queryMode: 'local',
name: 'uch',
emptyText: 'select..'
});
I have some items in my form and, when page is loaded, i put my combobox instead of one item in this form:


switchCombo = function(id) {
var field = searchForm2.items.get(6);
if (searchForm2.remove(field)) {

searchForm2.insert(6,{

layout: 'anchor',
fieldDefaults: {

labelAlign: 'top'

},
frame: true,
border: false,
baseCls:'x-plain',
items:[s_f_uch]

});

searchForm2.doLayout();

};
switchCombo();
}
first time, when page loaded, function puts combobox in right place and combobox works good, then i call my function again (switchCombo() ) and it remove an item correctly, then puts on it's place combobox again, but there is no expanding list in it..can't not select anything.

mitchellsimoens
15 Dec 2011, 2:10 PM
When you did the remove() it probably destroyed it. Try passing false as a 2nd argument to the remove()

ytppa
15 Dec 2011, 8:13 PM
Great thanks, Mitchell.
Also this topic (http://www.sencha.com/forum/showthread.php?17396-Hiding-the-combobox-and-the-label-sometime) helped me to solve my problem.
Very simple functions:

function hideField(field)
{
field.disable();// for validation
field.hide();
field.getEl().up('.x-form-item').setDisplayed(false); // hide label
}

function showField(field)
{
field.enable();
field.show();
field.getEl().up('.x-form-item').setDisplayed(true);// show label
}