Is there a best practice method, when taking input from a user (say picking from a list of items) to check if that item has already been chosen (the set of chosen things being in an apexDataArray?
Typescript has a bunch of examples of eliminating duplicates, but say you want to catch the user trying to add a duplicate?
A better way of course would be to filter the list of options by what was already selected, but we can ask that separately.
For example, have a list of options in a component, passed in by the owning UI page:
links → apexDataArray
And we have an AutoComplete serving up a bunch of business object values:
this.topics.setOption('where', where);
await this.topics.read();
and when something is chosen in the AutoComplete, we have a ‘add’ method being driven and add to the list:
const newLink = await this.links.add({ childTopicId: value.id });
But we want to check if the thing chosen (value which is an object in the example above) is already in the set of ‘links’ that were passed in (and where we’re maintaining our set of items)
Perhaps something like:
if (this.links.find((obj) => obj.childTopicId === value.id)) throw ???;