PDA

View Full Version : [Solved] ComboBox valueField,displayField,HiddenName



Nokia555
10 Feb 2010, 11:17 AM
Hello,

I have problem with my new script, i have tryd the HiddenName stuff, nothing works, always the wrong value.

I'm getting the values are like (ID,Name) Combobox should post the ID and show the Name.

Loader:

var mudelReader = new Ext.data.JsonReader({
id: 'mudelid',
name:'mudelid'
}, [ 'sid', 'mudelnimi']);

var mudels = new Ext.data.Store({
proxy: new Ext.data.HttpProxy({
url: 'json/mudelid.php'
}),
reader: mudelReader,
remoteSort: false
});

mudels.load();


ComboBox Field:

mudelField = new Ext.form.ComboBox({
id:'mudels',
fieldLabel: 'Mudel',
allowBlank: false,
typeAhead: true,
triggerAction: 'all',
store:mudels,
mode: 'local',
displayField: 'mudelnimi',
hiddenName:'mudelnimi',
valueField: 'sid',
anchor:'95%'
});

I have more than 1 combobox in the code, i have set different ids,name.

For example i use car models like (Audi A6), ID: 9 Name: A6, it most display 9 but it display A6

Can somebody help me with that? I'm trying to find the way more than 4 hours for now.

Eugen_
10 Feb 2010, 11:33 AM
Hi, Nokia555

maybe





var mudelReader = new Ext.data.JsonReader({
id: 'sid',
name:'mudelid'
}, [ 'sid', 'mudelnimi']);

var mudels = new Ext.data.Store({
proxy: new Ext.data.HttpProxy({
url: 'json/mudelid.php'
}),
reader: mudelReader,
remoteSort: false
});

mudels.load();


mudelField = new Ext.form.ComboBox({
id:'mudels',
fieldLabel: 'Mudel',
allowBlank: false,
typeAhead: true,
triggerAction: 'all',
store:mudels,
mode: 'remote',
displayField: 'mudelnimi',
hiddenName:'sid',
valueField: 'sid',
anchor:'95%'
});

Nokia555
10 Feb 2010, 11:45 AM
It didn't help :(
When i select A6 from combobox then its Ok, says the ID, but when i set some other field active and press save again, then its already A6



function isVaruosaValid(){
return(nimiField.isValid() && hindField.isValid() && catField.isValid() && markField.isValid() && mudelField.isValid() && lisainfoField.isValid() && mudeltField.isValid());
}

function resetVaruosaForm(){
nimiField.setValue('');
hindField.setValue('');
mudelField.setValue('');
lisainfoField.setValue('');
mudeltField.setValue('');
}

var mudelReader = new Ext.data.JsonReader({
id: 'sid',
name:'mudelid'
}, [ 'sid', 'mudelnimi']);

var mudels = new Ext.data.Store({
proxy: new Ext.data.HttpProxy({
url: 'json/mudelid.php'
}),
reader: mudelReader,
remoteSort: false
});

nimiField = new Ext.form.TextField({
id: 'nimi',
fieldLabel: 'Nimi',
maxLength: 20,
allowBlank: false,
anchor : '95%'
});

hindField = new Ext.form.TextField({
id: 'hind',
fieldLabel: 'Hind',
maxLength: 20,
allowBlank: false,
anchor : '95%'
});

catField = new Ext.form.ComboBox({
id:'cats',
name:'cats',
fieldLabel: 'Kategooria',
allowBlank: false,
typeAhead: true,
triggerAction: 'all',
store:cats,
mode: 'remote',
displayField: 'nimi',
valueField: 'id',
anchor:'95%'
});

markField = new Ext.form.ComboBox({
id:'mark',
name:'mark',
fieldLabel: 'Mark',
allowBlank: false,
typeAhead: true,
triggerAction: 'all',
store:margid,
mode: 'remote',
hiddenName:'nimi',
displayField: 'nimi',
valueField: 'mid',
anchor:'95%'
});

markField.on('select', function(combo, record, index) {
mudels.reload({params: {
smark: markField.getValue()
}})
});

mudelField = new Ext.form.ComboBox({
id:'mudels',
fieldLabel: 'Mudel',
allowBlank: false,
typeAhead: true,
triggerAction: 'all',
store:mudels,
mode: 'remote',
displayField: 'mudelnimi',
hiddenName:'mudelnimi',
valueField: 'sid',
anchor:'95%'
});

mudeltField = new Ext.form.TextField({
id: 'mudelt',
fieldLabel: 'Mudel Täpsustus',
maxLength: 20,
allowBlank: true,
anchor : '95%'
});


lisainfoField = new Ext.form.TextField({
id: 'lisainfo',
fieldLabel: 'Lisainfo',
maxLength: 20,
allowBlank: true,
anchor : '95%'
});


VaruosaForm = new Ext.FormPanel({
labelAlign: 'top',
bodyStyle:'padding:5px',
width: 600,
items: [{
layout:'column',
border:false,
items:[{
columnWidth:0.5,
layout: 'form',
border:false,
items: [nimiField, hindField, catField]
},{
columnWidth:0.5,
layout: 'form',
border:false,
items: [markField, mudelField, mudeltField,lisainfoField]
}]
}],
buttons: [{
text: 'Lisa ja sulge',
iconCls: 'add',
handler: lisavaruosa2
},{
text: 'Katkesta',
handler: function(){
// because of the global vars, we can only instantiate one window... so let's just hide it.
VaruosaCreateWindow.hide();
}
}]
});

function lisavaruosa2() {
alert(markField.getValue() + ' ' + mudelField.getValue());
}


VaruosaCreateWindow= new Ext.Window({
id: 'VaruosaCreateWindow',
title: 'Uue varuosa lisamine',
closable:true,
width: 610,
height: 300,
plain:true,
layout: 'fit',
items: VaruosaForm
});


function lisavaruosa(){
if(isVaruosaValid()){
Ext.Ajax.request({
waitMsg: 'Please wait...',
url: 'database.php',
params: {
task: "UUSVARUOSA",
userid: xidID,
nimi: nimiField.getValue(),
hind: hindField.getValue(),
cat: catField.getValue(),
mark: markField.getValue(),
mudel: mudelField.getValue(),
lisainfo: lisainfoField.getValue(),
mudel_t2psustus: mudeltField.getValue()
},
success: function(response){
var result=eval(response.responseText);
switch(result){
case 1:
Ext.MessageBox.alert('Creation OK','Uus toode on lisatud.');
VaruosadDataStore.reload();
VaruosaCreateWindow.hide();
break;
default:
Ext.MessageBox.alert('Warning','Toote lisamisel tekkis probleem.');
break;
}
},
failure: function(response){
var result=response.responseText;
Ext.MessageBox.alert('error','could not connect to the database. retry later');
}
});
} else {
Ext.MessageBox.alert('Warning', 'Your Form is not valid!');
}
}

function displayVaruosaWindow(){
if(!VaruosaCreateWindow.isVisible()){
resetVaruosaForm();
VaruosaCreateWindow.show();
} else {
VaruosaCreateWindow.toFront();
}
}

Eugen_
10 Feb 2010, 11:50 AM
Nokia555, see the example


var bFirstLoading = true;

var storeClinic = new Ext.data.Store({
url: '',
autoLoad: true,
reader: new Ext.data.XmlReader({
record: 'clinic',
id: 'clinic_id'
}, [
{name: 'clinic_id', type: 'int'},
{name: 'clinic_title', type: 'string'}
]),
listeners: {
'load': function(store, records, options) {
if (bFirstLoading) {
bFirstLoading = false;
/* I set current clinic_id here after first loading */
if (edit) {
comboClinic.setValue(record.get('clinic_id'));
}
}
}
}
});
var comboClinic = new Ext.form.ComboBox({
store: storeClinic,
name: 'clinic_id',
fieldLabel: 'Clinic',
displayField: 'clinic_title',
valueField: 'clinic_id',
emptyText: 'Select ...',
selectOnFocus: true,
editable: false,
triggerAction: 'all',
mode: 'remote',
forceSelection: true,
listeners: {
'beforequery': function(qe) {
delete qe.combo.lastQuery;
}
},
anchor: '100%'
});

to get the id


comboClinic.getValue()

to get the title


var record;
for (var i = 0; i < storeClinic.getCount(); i++) {
record = storeClinic.getAt(i);
if (comboClinic.getValue() == record.get('clinic_id')) {
alert(record.get('clinic_title'));
break;
}
}