Hi i need a kind of ComboBox mit input listener, but dont have an idea how to.
The user must be able to enter a word into a combobox and upon 3 letters, it must start a search in the database for matching items which then must be set to the ComboBox as chooseable values.
Am i right, that a ComboBox doesnt have this behaviour out of the box? Does anyone has an idea how to get this done?
This prints the entered value, looks good. Will try now add the database to it. ChatGPT recommended a Dataprovider with filter. Maybe also worth a look, but it looks quite more complicated for this use case.
It’s rare for me to say, but ChatGPT is right. DataProvider with a filter should be used. The implementation is really simple and no JavaScript hacks are necessary.
Delegating it to the data provider might even a better idea, simply did not pop-up in my mind
The data provider should be notified by the CB on filter change and could then, depending on the length of the string, return data or not (if length < 3).
Thanks for the feedback. In this case there are tons of data which needs to be loaded (the itemRenderer generates a div with user data, and more related data). Loading all those data would be a big overload, thats why we go this way with “you need to enter at least 3 letters”.
The user also knows, what he is looking for. He definetely knows for example the name of the user he is looking for. So the intend is, why laoding all Mr. Miller, if the user knows he looks for Mr. Smith :)
Not quite, but almost. You can do this by using backend data provider instead. The callback gets Query object as a parameter, and that has the Filter value populated. That is the same as the input value. So you do not need to set input listener. You can just implement the callback so that it does not return items before there are at least three characters in the filter value. And naturally then you implement your service query so that it can use the filter value accordingly. So your code is step to right direction.