PDA

View Full Version : Combobox Editable but allow only values from source



muselmanach
13 Feb 2013, 5:58 AM
Hello!

I have the following problem. I want a combox which is editable, so the user can type and the list will be filtered (so he hasnt to scroll through all entries), but i also want the combobox to be invalid if he enters a string which isnt in the list.

For example:

my list source would contain the following elements: AAA,AAB,AAC,BBA,BBC,BBB

so if the user enters AA, the combobox only shows AAA and AAB and AAC which is a correct behaviour.
but if the user now stops and goes to the next field in my form, the combobox should display that her value is invalid.

do you understand my problem?
is there a simple solution to this?

thx (need an urgent answer)
muselmanach

muselmanach
14 Feb 2013, 4:56 AM
anyone?

sword-it
14 Feb 2013, 5:19 AM
Hi muselmanach,

You can give "forceSelection:true" config to the combo, user can enter only buffered record.

muselmanach
14 Feb 2013, 6:38 AM
Now my Combobox looks like follow, but it still isnt doing what i need it to do:


{displayField:'displayField',forceSelection:true,
queryMode:'local',
store: myStore,
triggerAction:'all',
valueField:'id',
name:'supervisor',
fieldLabel:'Leiter',
xtype:'combobox',
id:'myComboBox',
width:500,
listeners:{
'beforequery':function(queryEvent){
queryEvent.query = new RegExp(queryEvent.query, 'i');
queryEvent.forceAll = true;}
}
}

if i enter an invalid string(an string which isnt contained in my source) into my combobox and then hit my save button (which checks if the form.isValid()). the form.isValid() is still true, though i entered an not exisisting string in my combobox.

do you know what i mean?

scottmartin
14 Feb 2013, 7:44 AM
Add allowBlank: true to your combo:
http://jsfiddle.net/SQ4Pd/

forceSelection:true will clear the combo and submit will see that it is blank

Scott.

muselmanach
14 Feb 2013, 8:14 AM
well, your example would work perfectly if i had to choose a value from combobox, but
i also want to be able to leave my combobox blank, if there is no supervisor needed.

but if i set allowBlank to true, then the isValid check isnt there anymore..

scottmartin
14 Feb 2013, 8:20 AM
Manually insert a 'no select' value to the store on the store load event .. that way you have your list of items, but the user can select a 'no select' value and still not be blank.

Scott.

muselmanach
14 Feb 2013, 8:38 AM
yes, i thought about this too, but i would like a "clean" way, without creating a "no instance", much better.

droessner
14 Feb 2013, 10:13 AM
You could add the following config to your combo. This will add a "clear" button next to the dropdown arrow button to clear out the combo value.



trigger1Cls: Ext.baseCSSPrefix + 'form-clear-trigger',
trigger2Cls: Ext.baseCSSPrefix + 'form-combo-trigger',
onTrigger1Click : function() {
this.setValue(null);
}