PDA

View Full Version : Issue in validating SimpleComboBox



apandey1
6 Jan 2012, 8:40 AM
I have issue in validating simplecombobox
Code for comboBox is :
SimpleComboBox<String> tf = new SimpleComboBox<String>();
tf.setStyleName("configSettingsComboBox");
tf.setTypeAhead(true);
tf.setForceSelection(true);
tf.setEditable(true);
tf.setTriggerAction(TriggerAction.ALL);
tf.setValidateOnBlur(false);

We are adding empty string along with list of values to SimpleComboBox. Empty string allows user to select value by typing initial character. When submitting form, we check that combobox value is not empty string, else we set error message using

tf.forceInvalid("Value cannot be empty");

However we found that forceInvalid method is not working, also we tried custom validator , but it does not get triggered when empty value is set in SimpleComboBox.
Using setAllowBlank(false) for SimpleComboBox is also not validating when empty string is selected.

How do we validate SimpleComboBox for empty value.

gishmo
9 Jan 2012, 6:36 AM
Did you try setAllowBlank?

WesleyMoy
9 Jan 2012, 12:39 PM
Because you've added an entry with value "", it's perfectly valid to select it. You could do things like listening for the BeforeSubmit event on the form and checking the value of the combo box.

More importantly, why do you need to add the empty string as a value? Your example seems to work fine without it. Typing a single letter results in the values beginning with that letter being shown in the dropdown. Have you tried just not adding the empty string value?