How To Re-Empty ComboBox when forceSelection is Set To TRUE (ExtJS 4)

Fitrah M picture Fitrah M · Feb 21, 2012 · Viewed 25k times · Source

I have a combo box with forceSelection config is set to true.

The combo box is optional. It can be empty.

If user choose one of the options and then re-empty the combo box, it doesn't want to be empty.

The combo box always restores the previously selected value.

It's ridiculous. It should be empty when user delete the value.

How to solve this problem? Is there a config that I missed?

Answer

Aurimas picture Aurimas · May 14, 2012

I've solved this problem with 'change' listener. Example code snippet

addListener('change', function() {
  if (this.getValue() === null) {
    this.reset();
  }
});

When you delete selected value, the ComboBox value is set to null. So you you could just check for that value & restore the ComboBox value to default one.