Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

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?

like image 954
Fitrah M Avatar asked Feb 21 '12 03:02

Fitrah M


3 Answers

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.

like image 97
Aurimas Avatar answered Sep 20 '22 06:09

Aurimas


could you replace forceSelection with allowEmpty: false? In my view forceSelection is doing completely what it should do - it force user to select something from the list. Another option is to add one extra item in the list - like None for example. So user could select it.

like image 44
Andrey Selitsky Avatar answered Sep 23 '22 06:09

Andrey Selitsky


I've also hit the same problem with the combos, and unfortunately the best solution I came up with was a img/button for clearing the selected value, then hooking up the following using jQuery:

        $('#imgId').click(function () { 
            var combo = Ext.getCmp('cmpId');
            combo.setValue(null);
            combo.setRawValue(null);
        });

Not ideal, but I think it's fairly clean and user friendly. Hope it helps.

like image 40
Amalea Avatar answered Sep 23 '22 06:09

Amalea