Combobox with custom values allowed fails validation

Hi all,

what is the correct way to use a combobox with custom values together with the binder?

This doesnt work as expected:
cb.setRequired(true);
cb.setAllowCustomValue(true);
cb.addCustomValueSetListener(event → {
cb.setValue(event.getDetail());
});
cb.setErrorMessage(“Error”);

Maybe this is not even fixed yet?:

https://vaadin.com/forum/thread/17690613/combobox-with-custom-values-fails-required-validation

The added item has to be added to the server side list, otherwise it’s an unknown value for the server and is rejected because of security reasons.

And that means what?

Does that mean custom value combo box cannot be combined with binder? I assume the binder always checks the value of the cb first before I am even able to add it to the server side.

In your listener add the item also to the list of items.

Yes this works. Thanks!

cb.addCustomValueSetListener(e → {
items.add(e.getDetail());
cb.setItems(items);

        cb.setValue(e.getDetail());
    });

@resilient-meerkat probably something for the docs where you showcase custom values :slightly_smiling_face:

Yeah, would be good to document. I don’t have the capacity to do it now, though

me neither, but someone could at least make a ticket in https://github.com/vaadin/docs

Done

https://github.com/vaadin/docs/issues/1837

I hope the issue makes sense. I am very unsure on how to write issues…

It’s a bit light on details, but good enough. Thanks for creating it!