vaadin-component-factory / lookup-field-flow

Java API for a Lookup Field in Vaadin
https://componentfactory.app.fi/lookup-field-flow-demo/
Apache License 2.0
0 stars 1 forks source link

ItemLabelGenerator should be different between field and dropdown list #6

Open JariHanah opened 3 years ago

JariHanah commented 3 years ago

When the user searches for a customer with alot of details, phone, or name, or address, the dropdown might need a specialized itemRenderer to give the user the info needed to pick the right customer,

When he selects some customers, the LookUpField should render this info selected differently, as the user only needs a name for example to be seen in the field.

The current implementation has only one ItemRenderer for both the LookupField and the DropDown list.

the API should include this for example:

setItemLabelGeneratorForLookUpField(new ItemLabelGenerator<City>(){
            @Override
            public String apply(Customer t) {
                return t.getName()

            }

        });
}
setItemLabelGeneratorForDropDown(Customer t){
 @Override
            public String apply(Customer t) {
                return t.getName()+t.getAddress();

            }

        });
}

I hope the issue is explained clearly, and thank you for your great work!!!

jcgueriaud1 commented 3 years ago

Currently the component only offers setItemLabelGenerator which renders both. You can get the combobox from this API: lookupField.getComboBox()

Which gives you the access to all the methods of the Combobox (in single select) or the MultiselectComboBox (in multiple select). You can use a renderer for the combobox:

lookupField.getComboBox().setRenderer(new ComponentRenderer<>(s -> {
            return new Div(VaadinIcon.ABACUS.create(), new Span(s));
        }));

Which only renders the dropdown content.

The search is still done based on setItemLabelGenerator.

In your case:

lookupField.getComboBox().setItemLabelGenerator( t -> t.getName());
lookupField.getComboBox().setRenderer(new TextRenderer<>(t -> t.getName()+t.getAddress()));

But if you're searching for "Dallas" you won't find some who is living in Dallas.