3

I'm developing an extjs 6 application and recently figured out that it's not possible to set the value of a ComboBox using the setValue(value) method when its store doesn't contain a record with a valueFiled equals to value as described here http://docs.sencha.com/extjs/6.0/6.0.0-classic/#!/api/Ext.form.field.ComboBox-method-setValue.

So my question is is there any other way to change the value of the ComboBox when its store is empty (or doesn't contain a record with valueFiled equals to value) ?

hzitoun
  • 5,492
  • 1
  • 36
  • 43
  • Try the [`select()`](http://docs.sencha.com/extjs/6.0/6.0.0-classic/#!/api/Ext.form.field.ComboBox-method-select) method. – CD.. Dec 21 '15 at 16:36
  • I don't understand... according to the doc `select( combo, record, eOpts )` **Fires when at least one list item is selected** I don't have any element in my store (its empty) so is the list of items... moreover this method is not used to change value – hzitoun Dec 21 '15 at 16:38
  • I don't think the `select()` method (not event) will work, because in the code that method just calls `setValue()` internally. Why are you trying to set a value when there isn't a list of values to choose from? Maybe you can use the `emptyText` config to display a value when none is set? – cpastore84 Dec 21 '15 at 16:43
  • Actually it is an old functional behaviour that was developed with extjs 1 and I'm trying to migrate to version 6. In that version we could set any value to the comboBox regardless the state of the store. For `emptyText ` it's not a solution because the value to set to the comboxBox changes depending on other value selected before... – hzitoun Dec 21 '15 at 16:53

2 Answers2

2

You want setRawValue() instead of setValue()

bhutten
  • 526
  • 3
  • 5
  • I ended up using this method, but I had to check if my store is empty or doesn't contain a record with `valueFiled` equals to `value` before using it. Something like this ` if (item && item instanceof Ext.form.field.ComboBox && item.getStore().getData().length === 0) { item.setRawValue(value); } else { item.setValue(value); }` – hzitoun Dec 22 '15 at 09:53
1

You figured it wrong. Please have a look at https://fiddle.sencha.com/#fiddle/12t4, where I got it to work without any problem.

Please check whether it is possible that you have set forceSelection: true on your combo, as this would induce the behaviour you described.

Alexander
  • 19,906
  • 19
  • 75
  • 162
  • Actually your example is wrong (compared to my question), just add a `valueField : 'attribute'` to your comboxBox and your example won't work any more... https://fiddle.sencha.com/fiddle/12t4. Concerning `forceSelection`, it's kept by default (false)... – hzitoun Dec 22 '15 at 09:35
  • I have added `valueField: 'attribute'` to the example. I don't see any change in behaviour. It is still working. – Alexander Dec 22 '15 at 09:43
  • Sorry I gave you the wrong link, check this https://fiddle.sencha.com/#fiddle/12to – hzitoun Dec 22 '15 at 09:51
  • I am trying to match your code to your question. Your question is obviously incomplete. – Alexander Dec 22 '15 at 14:02