So ABP has a kind of helper to select elements that uses select2 under the hood. I already consulted the docs but didn't find anything. So basically I have a cshtml element that looks like the default element in ABP's autocomplete manual, but the problem is that only a property for the id and one for the text can be returned (autocomplete-display-property-name and autocomplete-value-property-name). I know in select2 you can describe in the processResults option the name of the properties you want. This is crucial for me because the id and text properties are not enough to point to an unique result, so I cannot really do a separate api request or something after the select event.

Could I maybe overwrite ABP via some .js code(I tried to in many ways but it didn't work)?

jsotola's user avatar

jsotola

2,2541 gold badge16 silver badges32 bronze badges

lilnoob's user avatar

The primary problem is the architecture of the framework. ABP's autocomplete initializer wraps the `processResults` method internally during dom initialization. It only maps the `id` and `text` fields, ignoring all the rest of the payload sent in the api response.

In order to get around this issue, I came up with three solutions:

The Best/Most Flexible Way: Stop Using the Tag Helper for this particular Field

Don't fight with the framework and force `<abp-select>` to do something it cannot, instead, just fall back to native HTML and use a regular `<select>` for this particular field, then activate Select2 by hand with a little JS. This brings us to 100% control of the `processResults` function. I can take the `data.items` from the API and map them to add extra properties. Then I can easily catch that extra property when the `select2:select` event is triggered and run a separate API request without any trouble.

nada adel's user avatar

New contributor

nada adel is a new contributor to this site. Take care in asking for clarification, commenting, and answering. Check out our Code of Conduct.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.