We really like the implementation of igxComboAddItem, but we cannot find out the best way to make it work in our environment.
When a user requests that a new item be added to a lookup list, we fire an API request to validate the entry (i.e. not all spaces, not duplicate), ensure the user has the appropriate authority to perform the action, and then finally store it in the DB.
When the value is stored in the DB, it will have a numeric key generated which is needed to successfully add the entry to the list.
We can figure out how to perform this work in the onAddition method (we can do it synchronously if needed), but what we can figure out yet is how to cancel the add operation if one of the business rules fails in the API call.
One option might be to reset the new list of items and then update it when the operation has completed (this approach could also support async operations).
Another option might be to replace the addItem's click event when combo is opening.
Both of these options seem somewhat drastic, so we were hoping there was a better, standard way of doing this work.
Hi Lance,Thanks for reaching out!I think the best approach would be to template the "Add Item" button and prevent event propagations from it (since the handler is on the wrapper). Afterwards handle the event and, since the combo is data bound, add the item to the data and select it and it would render properly.Here's a StackBlitz illustrating the approach.That being said, the combo's "onAddition" event really should be cancelable - I've logged an enhancement on our github repo. It should be implemented in time for the 12.0.x release, which should drop sometime next month.Let me know if this works for you or if you have any questions.Regards,Viktor Slavov
Thank you for the very helpful response and sample.
We have taken a slightly different (and non-standard) approach, but may revisit this implementation in the future.
Hello Lance,
I am glad that you find Victor`s suggestion helpful.
Please let us know if you need any further assistance.