PDA

View Full Version : ComboBox - Store



bauchinj
5 Nov 2009, 1:57 AM
Hello!

I have some questions on ComboBox.

Let's start with some code:



var maingroup = new Ext.data.Store({
reader : new Ext.data.JsonReader({
fields : ['name'],
root : 'rows'
}),
proxy : new Ext.data.HttpProxy({
url : 'php/getCombo.php'
}),
autoLoad : true
});

...

ctrContainer.add({
xtype : 'form',
id : 'ctrForm',
border : false,
labelWidth : 150,
defaults : {
width : 150
},
items : [{
xtype : 'combo',
name : 'maingroup',
fieldLabel : 'Combo',
mode : 'local',
displayField : 'name',
store : maingroup
}]
});

getCombo.php return following json:


{"rows":[{"name":"master"},{"name":"admin"}]}

So here my first question:
If I select one of the options, I just be able to see this option. So when I want to select another option, I have to clear the selected, then I see all again. Is it possible to show always all options?


2.)
When I load the form, I'd like to select already an option of this comboBox. For example, I save some userdata in database, with the comboBox is the country to select. So the user save this. Next time he want to chang the country for this user again, but which country is selected? how can I say, which option should be selected, when loaded?


rgds

bauchinj
5 Nov 2009, 2:11 AM
I just detected a third question:

Is it possible to lock to save it's own entry (for instance, the user would save a fiction-country), so that the user just can select the options, he get from the server?

carol.ext
5 Nov 2009, 7:26 AM
1. triggerAction: 'all'

2. have you tried setting value in config?

3. What?

bauchinj
5 Nov 2009, 10:49 PM
1+2 Thank you

3:
For example:

ComboBox store:
*) France
*) Italy
*) England
*) USA

The user shouldn't be able to make a new (own) entry for instance 'London'.

Hope you know what I mean!

carol.ext
6 Nov 2009, 6:29 AM
3:
For example:

ComboBox store:
*) France
*) Italy
*) England
*) USA

The user shouldn't be able to make a new (own) entry for instance 'London'.

Hope you know what I mean!

Read about the below config options for ComboBox (http://www.extjs.com/deploy/dev/docs/?class=Ext.form.ComboBox). It sounds like you will want to force selection. You may or may not want to change editable from the default of true.

editable: false

forceSelection: true

NoahK17
6 Nov 2009, 12:53 PM
Yeah, forceSelection: true is what you're looking for with the 3rd question. It will make sure they can't type in their own text in the ComboBox.