PDA

View Full Version : (Resolved) Problem posting value combo - sends the description instead of the id



fabiojpoli
13 Sep 2010, 4:08 AM
Good day, ext combo is giving me tremendous headaches.

I have a form with multiple combos, I have the problem, by submitting the form, time sends the id of the option combo, hours sends the description, and logical that I need to send me the id.

For example, when I select a record to edit, the form is populated with information, including the UF (combo) of this record, to save this record, it sends the id of the UF , sometimes I edit the same record, and sends the description of the UF , at times the id, the description sometimes ... how to fix it? has some configuration that is always the combo with the id and not the description so that I can always send the id in the post?

the combo store

this.storeUf = new Ext.data.JsonStore({
autoLoad: true,
//storeGroup: this.sg,
url: 'include/secretaria/membroAction.php?action=listarUf',
root:'rows',
fields: [
{name: 'id'},
{name: 'uf'}
]
});combo

this.comboUf = new Ext.form.ComboBox({
fieldLabel: 'UF',
id:'uf',
store: this.storeUf,
typeAhead: true,
selectOnFocus: true,
width : 45,
mode: 'local',
triggerAction: 'all',
forceSelection: true,
valueField : 'id',
displayField : 'uf',
hiddenName: 'id_uf',
allowBlank: false,
listeners: {
scope:this,
select: function(){
this.listarCidades(this.comboUf, this.comboCidade)
}
}
});submit form

salvarMembro : function()
{
var form = this.membroForm.getForm();

if(!form.isValid()){
msgAlerta('Preencha os campos corretamente.');
return false;
}

//crio uma máscara
//this.el.mask('Salvando registro...');

/*
* Submitando formulário
*/
form.submit({
url : 'include/secretaria/membroAction.php',
params : {
action : 'cadastrarMembro'
},
scope:this,
success: function(f,a) //ao terminar de submitar
{
var json = Ext.decode(a.response.responseText);

this.el.unmask();
msgSucesso(json.msg);
this.setIdMembro(json.idMembro);
this.storeHistorico.load({
params: {idMembro: this.idMembro}
});
Ext.getCmp('tabHistoricoMembro').enable();
Ext.getCmp('tabPanelMembro').setActiveTab(2);

/*
* Muito importante! Aqui o evento salvar é disparado. Todos os listeners que foram associados
* a esse evento serão notificados, como por exemplo, o listener onSalvarMembro da
* classe MembroLista.
*/
this.fireEvent('salvar',this);
},
failure: function(f,a) {
var json = Ext.decode(a.response.responseText);
this.el.unmask();
msgErro(json.msg);
}
});
},to select a record to edit:


show: function()
{

MembroCadastro.superclass.show.call(this, arguments);

this.membroForm.getForm().reset();

// Pegando a TAG da Imagem.
var el = Ext.get("fotoMembro");

// Setando o novo atributo da Imagem conforme ID.
el.set({src: 'fotos/'+ this.idMembro +'.jpg'});

Ext.getCmp('tabPanelMembro').setActiveTab(0);
//this.sg.loadAll({maskEl:this.body, maskText:'Carregando...'});

if(this.idMembro !== 0){


this.el.mask('Carregando...');

this.storeMembro.load({
params: {idMembro: this.idMembro},
scope: this,
callback:function(){
this.membroForm.getForm().loadRecord(this.storeMembro.getAt(0));
this.carregarCombos(this.storeMembro.getAt(0).data);
}
});

Ext.getCmp('tabHistoricoMembro').enable();
}
else{

this.comboCidade.disable();
this.comboConjuge.disable();
Ext.getCmp('checkConjuge').disable();
Ext.getCmp('novoConjuge').disable();
Ext.getCmp('btnNovoConjuge').disable();
Ext.getCmp('data_casamento').disable();
this.comboCidadeNasc.disable();
Ext.getCmp('possui_cartao').disable();
Ext.getCmp('selo_ano').disable();
Ext.getCmp('codigo').disable();
Ext.getCmp('data_batismo').disable();
this.comboMinisterio.disable();

Ext.getCmp('tabHistoricoMembro').disable();
}

this.storeHistorico.setBaseParam('idMembro',this.idMembro);
Ext.getCmp('paginacaoHistorico').doRefresh();
this.storeHistorico.removeAll();
},
function executed to load the combo and keep down fill with the id instead of description


carregarCombos: function(dados)
{
if(dados.id_uf && this.comboUf.store.getCount() == 0){
var novaUf = new this.comboUf.store.recordType({
id : dados.id_uf,
uf : dados.uf
});

this.comboUf.store.insert(0,novaUf);
this.comboUf.setValue(dados.id_uf);
}
...
Thanks!

13 Sep 2010, 4:27 AM
I shudder when I see static ids and Ext.getCmp inside code that is designed to be in a class.

13 Sep 2010, 4:28 AM
your code seems OK. What happens if you do console.log(this.comboUf.getValue()) ? do you get the id instead of description?

fabiojpoli
13 Sep 2010, 4:55 AM
your code seems OK. What happens if you do console.log(this.comboUf.getValue()) ? do you get the id instead of description?

What do you mean with: "I shudder when i see static ids and Ext.getCmp inside code that is designed to Be in a class."?

At the time of post, send firebug:
id_uf = AC
sometimes
id_uf = 1

console.log (this.comboUf.getValue ()) returns:

>>> Console.log (this.comboUf.getValue ())
AC
undefined

13 Sep 2010, 5:03 AM
What do you mean with: "I shudder when i see static ids and Ext.getCmp inside code that is designed to Be in a class."?


Because it is an anti-pattern. Do not put static IDs on a class where you can have more than one instance of an object -- it's just flawed thinking.





At the time of post, send firebug:
id_uf = AC
sometimes
id_uf = 1

console.log (this.comboUf.getValue ()) returns:

>>> Console.log (this.comboUf.getValue ())
AC
undefined

I can't tell what exactly you're doing to retrieve the value. I've never seen the combo act this way unless a developer has done something hokey, like try to create more than one instance of a combo with the same ID.

fabiojpoli
13 Sep 2010, 5:11 AM
I have drawn from this example:
http://www.extdesenv.com.br/tutoriais-estudos/crud-avancado-com-ext-js-3-0/

fabiojpoli
13 Sep 2010, 7:54 AM
I have drawn from this example:
http://www.extdesenv.com.br/tutoriais-estudos/crud-avancado-com-ext-js-3-0/

Does anyone know another way to fix the problem that the combo does not show the id when editing a record, but his description is loaded? Maybe this solves the problem.

An override may

fabiojpoli
14 Sep 2010, 3:26 AM
Good morning, the problem I was having is that if they ever got into this (this.comboUf.store.getCount () == 0) was false, then it was not this (this.comboUf.setValue (dados.id_uf) ;)


carregarCombos: function(dados)
{
if(dados.id_uf && this.comboUf.store.getCount() == 0){
var novaUf = new this.comboUf.store.recordType({
id : dados.id_uf,
uf : dados.uf
});

this.comboUf.store.insert(0,novaUf);
this.comboUf.setValue(dados.id_uf);
}
...

I switched to this and it worked

if(dados.id_uf){
if(this.comboUf.store.getCount() == 0){
var novaUf = new this.comboUf.store.recordType({
id : dados.id_uf,
uf : dados.uf
});

this.comboUf.store.insert(0,novaUf);
}
this.comboUf.setValue(dados.id_uf);
}

Another problem I had is with the combo city did it and kept bringing the id in the combo instead of description

if(dados.id_cidade){
if(this.comboCidade.store.getCount() == 0){
var novaCidade = new this.comboCidade.store.recordType({
id : dados.id_cidade,
descricao : dados.cidade
});

this.comboCidade.store.insert(0,novaCidade);
}
this.comboCidade.setValue(dados.id_cidade);
this.comboCidade.store.load({
params: {id_uf: dados.id_uf}
});
this.comboCidade.enable();
}
else{
this.comboCidade.reset();
this.comboCidade.disable();
}

To resolve this, use the Rodrigo override: http://blog.rkn.com.br/2009/11/ext-ux-storegroup-carregando-dependencias/

Despite becoming a bit slow loading, solved the problem for hours.

Thanks!