Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ComboBox.setValue(null) does not clear ComboBox after the items has been set #9047

Closed
mvysny opened this issue Apr 10, 2017 · 20 comments
Closed

Comments

@mvysny
Copy link
Member

mvysny commented Apr 10, 2017

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.

@mvysny
Copy link
Member Author

mvysny commented Apr 10, 2017

vaadin-app.zip

@pinonpierre
Copy link

I have the same issue in my project

@OldIMP
Copy link

OldIMP commented Jun 9, 2017

Vaadin 8.0.6 the same

@viydaag
Copy link

viydaag commented Jun 20, 2017

I confirm I have the same issue with Vaadin 8.0.6

@zanonmark
Copy link

Same here, 8.0.6 (I don't know about previous versions, but 7.x was ok).

@sebastianfilke
Copy link

I can confirm this bug. Is there any plan to fix this soon?

@simon-chromow
Copy link

simon-chromow commented Oct 12, 2017

Reproducible in 8.1.5

@bassmartin
Copy link

Still an issue in 8.3.1

@mpt74
Copy link

mpt74 commented Mar 8, 2018

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));
    }		
}

@bassmartin
Copy link

I implemented @mpt74 solution and it works for my use case.

Thanks.

@tsuoanttila
Copy link
Contributor

Seems to be fixed with #10796. I will add a regression test for this.

@andreika63
Copy link

andreika63 commented Apr 14, 2018

Hi!
8.3.2 - the same bug

@TatuLund
Copy link
Contributor

@andreika63 Fix @tsuoanttila is referring to has not been merged yet. Maybe we can squeeze it to 8.4.0.

@nixty
Copy link

nixty commented Jul 10, 2018

Hi!
8.4.4 - the same bug

@tsuoanttila
Copy link
Contributor

@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?

@AndreiBoaghe
Copy link

AndreiBoaghe commented Aug 17, 2018

@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 :)

@mstahv
Copy link
Member

mstahv commented Nov 12, 2018

This issue was already resolved in 8.5 release. I guess there was another similar issue. Closing...

@mstahv mstahv closed this as completed Nov 12, 2018
@OldIMP
Copy link

OldIMP commented Nov 12, 2018

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

@mstahv
Copy link
Member

mstahv commented Nov 15, 2018

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.

@OldIMP
Copy link

OldIMP commented Nov 19, 2018

@mstahv thx 4 feedback. I've found #10641 for this issue

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests