View Full Version : [FNR] GXT 2.2.4 ComboBox force selection fails is ComboBox never expanded

16 May 2011, 4:37 PM
The ComboBox setForceSelection does not force a selection if the ComboxBox is never expanded and lazy render is true (the default).

To preproduce:

Create a ComboBox with edit true and forceSelection true
Quickly type characters in the box that will not trigger the expansion of the combo options
Click or tab out of the box

Expected Result:
The combo should force a selection to the last selected option in the combo's list, but it does not - the invalid text is left unvalidated.

If instead you type one letter that triggers the expansion or click the trigger your self then the combo will force a selection when you tab out.

Cause and Workaround:
This issue is caused by the lazy rendering - doForce() calls getValue() which returns the value because the field "initialised" is still false - it should return null because the invalid vale is not in the store's models. The "initialised" field only gets set to true when the combo is expanded.

The workaround is to disable lazy rendering (which creates the combo list and sets "initialised" to true).

Ideally you should not have to disable lazy rendering to have force selection work correctly.

Here is the code to reproduce the issue. Note if you don't set a simple value then you get a validation error (but instead you should get a forced selection)

public class ComboBoxBug implements EntryPoint
public void onModuleLoad()
FormPanel formPanel = new FormPanel();

final SimpleComboBox<String> aCombo = new SimpleComboBox<String>();
aCombo.setFieldLabel("Validate issue");
aCombo.add(Arrays.asList(new String[] {"AAA", "AAB", "AAC"}));
// GXT bug - if lazy render & not expanded list yet & type invalid text then doforce fails

30 Jun 2011, 1:19 PM
Any updates on this bug?

30 Jun 2011, 11:02 PM
As workaround you can set lazy render to true.

You could comment out the block in getValue that checks for initialzed, or you could use the workaround for now.

We could also force the list initialization in a forceselect. This would not be a huge change in behaviour, any thoughts?

30 Jun 2011, 11:26 PM
Index: user/src/com/extjs/gxt/ui/client/widget/form/ComboBox.java
--- user/src/com/extjs/gxt/ui/client/widget/form/ComboBox.java (revision 2407)
+++ user/src/com/extjs/gxt/ui/client/widget/form/ComboBox.java (working copy)
@@ -551,6 +551,7 @@
return value;
if (store != null) {
+ store.clearFilters();

@@ -1001,6 +1002,10 @@

+ if (!initialized) {
+ createList(true);
+ }
if (getValue() == null) {
if (lastSelectionText != null && !"".equals(lastSelectionText)) {

Also i am not normally posting a patch to the public, i think its the best for here. If you have any time, you maybe want to test this change and report back here.

6 Jul 2011, 10:39 PM
you maybe want to test this change and report back here.

Sven, this fix works for me - not sure what effect the store.clearFilters() has, but I see no ill effects so far.

Can you sent the rev number when you commit?


13 Sep 2011, 5:24 AM
Fixed in SVN as of revision 2429