We want something that is a combination between the ComboBox and the AutoComplete. Basically, we need to have a control that works exactly like the ComboBox about 99% of the time - only allowed items can be selected, we need to know the id of the selected item, an onChange event (or equivalent) must be handled, etc. However, we also have a request that users can retrieve a subset of the items based on what they type into the control. The data must also include an "Any" option that is not returned with the Input data for the parent component.
Currently, we are using the ComboBox with suggest and filterable set to true. We are adding the "Any" in ngOnInit and ngOnChanges as needed by calling the following:
resetItemData() {
this
.allItems = [
this
.anyItem, ...
this
.myComponent.items];
this
.filteredItems =
this
.allItems;
}
The ComboBox uses filteredItems as its data and we are setting the initial value to be anyItem which has an id = 0. We are using the valuePrimitive because we need to run another event when any inputs change on the form, so we need to run the valueChange event on the ComboBox. We are also using the filterChange to filter the items shown based on what the user types in.
When the user types in something that does not match, we are setting the filteredItems to return allItems just as we do at the beginning so that the user can just select something from the list. If the user selects nothing, we set the value to be 0 so that the request will use "Any" because the API will not accept an invalid itemId.
Everything is working as designed. However, we have a couple UI issues that need to be addressed before we can proceed.
- If the user types in something invalid and switches focus, the text is removed, but "Any" is not shown - even though the value is reset to 0. Is there a defaultValue or some way to programmitically insert text into the ComboBox input?
- When the user is typing in text, the popup with the suggestions blocks the bottom 50% of the text in the input. Is there a way to push this popup lower? I looked at the CSS rendered for the popup, but it appears to be calculated based on the position that the ComboBox is in the browser window. I tried adding something to the popupSettings parameter, but it did not seem to recognize my changes. This is slightly annoying when the filteredItems have some items, but it is really a deal-breaker when the user types in something that has no matches because a big empty window blocks the text.
Any suggestions you could give on this would be helpful! I have tried using AutoComplete, but it appears that there are even more issues to address. However, if you know of a way to use that instead of the ComboBox, I am open to that as well.
Thank you for your help!