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

ItemLabelGenerator should be different between field and dropdown list #6

Open
JariHanah opened this issue Oct 31, 2021 · 1 comment
Labels
enhancement New feature or request

Comments

@JariHanah
Copy link

JariHanah commented Oct 31, 2021

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
Copy link
Contributor

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.

@bwajtr bwajtr added the enhancement New feature or request label May 29, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants