The_Jackal
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.setName("field");
aCombo.add(Arrays.asList(new String[] {"AAA", "AAB", "AAC"}));
aCombo.setEditable(true);
aCombo.setForceSelection(true);
aCombo.setTypeAhead(true);
aCombo.setAllowBlank(false);
aCombo.setTriggerAction(TriggerAction.ALL);
aCombo.setSimpleValue("AAA");
// GXT bug - if lazy render & not expanded list yet & type invalid text then doforce fails
//aCombo.setLazyRender(false);
formPanel.add(aCombo);
RootPanel.get().add(formPanel);
}
}
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.setName("field");
aCombo.add(Arrays.asList(new String[] {"AAA", "AAB", "AAC"}));
aCombo.setEditable(true);
aCombo.setForceSelection(true);
aCombo.setTypeAhead(true);
aCombo.setAllowBlank(false);
aCombo.setTriggerAction(TriggerAction.ALL);
aCombo.setSimpleValue("AAA");
// GXT bug - if lazy render & not expanded list yet & type invalid text then doforce fails
//aCombo.setLazyRender(false);
formPanel.add(aCombo);
RootPanel.get().add(formPanel);
}
}