Vaadin 8.0.5
The below code works flawlessly and clears the ComboBox selection:
combo.setValue(null);
combo.setItems("" + System.currentTimeMillis());
Yet, the code below does not work and the previous value stays selected in the combo box:
combo.setItems("" + System.currentTimeMillis());
combo.setValue(null);
Please see the sample app attached.
To reproduce the issue, press the "Reset" button, then select a value and press the "Reset" button again. Expected behavior: the value is cleared. Actual behavior: the value is not cleared.
I have the same issue in my project
Vaadin 8.0.6 the same
I confirm I have the same issue with Vaadin 8.0.6
Same here, 8.0.6 (I don't know about previous versions, but 7.x was ok).
I can confirm this bug. Is there any plan to fix this soon?
Reproducible in 8.1.5
Still an issue in 8.3.1
I am not sure if I get what the problem is, but I simply could not clear the ComboBox, when the binding BEAN has changed (and a new BEAN has a null in the corresponding field)
I fixed it by creating so called ClearableComboBox, with one overriden method:
public class ClearableComboBox<T> extends ComboBox<T> {
public ClearableComboBox(String in) {
super(in);
}
protected void setSelectedFromServer(T item) {
String key = itemToKey(item);
T oldSelection = getSelectedItem().orElse(getEmptyValue());
doSetSelectedKey(key);
fireEvent(new SingleSelectionEvent<>(ClearableComboBox.this, oldSelection, false));
}
}
I implemented @mpt74 solution and it works for my use case.
Thanks.
Seems to be fixed with #10796. I will add a regression test for this.
Hi!
8.3.2 - the same bug
@andreika63 Fix @tsuoanttila is referring to has not been merged yet. Maybe we can squeeze it to 8.4.0.
Hi!
8.4.4 - the same bug
@nixty due to changes in the API, the fix has only been available for 8.5. Can you test 8.5.0.beta1 or 8.5-SNAPSHOT and see if it works for you?
@tsuoanttila
Hi!
I have tested with 8.5.1 and I haven't be able to reproduce this bug.
So, it seems to be fixed :)
This issue was already resolved in 8.5 release. I guess there was another similar issue. Closing...
It would be nice if comboBox.setItems() could also clear the current value.
ComboBox<Object> comboBox = new ComboBox<>();
comboBox.setItems(1, 2, 3);
addComponent(comboBox);
addComponent(new Button("set new items", e -> comboBox.setItems(4, 5, 6)));
To reproduce, select 1 at first, and click the button "set new items", then _1_ will stay in the ComboBox and cannot be deleted
That is a different issue. Please create a new one, but I think the issue is bit controversial.
IIRC in Vaadin 7 we verified that the value is available, but it is left out because of performance reasons. It might be that we'll do nothing for this, especially as it is very easy for developer to clear the value if needed.
@mstahv thx 4 feedback. I've found #10641 for this issue
Most helpful comment
@tsuoanttila
Hi!
I have tested with 8.5.1 and I haven't be able to reproduce this bug.
So, it seems to be fixed :)