PDA

View Full Version : [SOLVED] Combobox change xtype from formfield



danielbertini
10 Oct 2010, 2:04 PM
Hello all, how can i do to change xtype from a form field when user change combobox?
Example: When user select "porcentagem" i need change xtype from "desconto" to numberfiled, when user select "Valor fixo" i need change xtype from "desconto" to moneyfield.

My code is:



var promotionAddForm = new Ext.form.FormPanel({
url: base_url+'marketing/promotion/add',
frame: false,
border: false,
baseCls: 'x-plain',
labelAlign: 'right',
monitorValid: true,
plain: true,
labelWidth: 130,
defaults: {
labelStyle: 'font-size:11px; color:#333; font-weight:bold;',
xtype: 'textfield',
anchor: '90%'
},
items:[{
fieldLabel: 'Nome',
name: 'name',
allowBlank: false
},{
xtype: 'combo',
fieldLabel: 'Status',
name: 'status',
triggerAction: 'all',
editable: false,
anchor: '90%',
allowBlank: false,
store: ['Ativa','Inativa']
},{
xtype: 'combo',
fieldLabel: 'Tipo de desconto',
name: 'discount_type',
triggerAction: 'all',
editable: false,
anchor: '90%',
allowBlank: false,
store: ['Porcentagem','Valor fixo'],
listeners :{
'select':function(combo, record, idx){
if(idx === 0){
alert('porcentagem...');
}
if(idx === 1){
alert('valor fixo...');
}
}
}

},{
xtype: 'moneyfield',
fieldLabel: 'Desconto',
name: 'discount_value',
allowBlank: false
},{
labelStyle: 'font-size:11px; color:#333; font-weight:normal;',
xtype: 'datefield',
editable: false,
fieldLabel: 'Data de início',
name: 'date_to_start'
},{
labelStyle: 'font-size:11px; color:#333; font-weight:normal;',
editable: false,
xtype: 'datefield',
fieldLabel: 'Data de término',
name: 'date_to_end'
}]
});

Condor
11 Oct 2010, 1:23 AM
You can't change the xtype of a field.

Instead, add both fields and hide+disable one of them.

danielbertini
11 Oct 2010, 7:58 PM
Ok, thanks!