This is a migrated thread and some comments may be shown as answers.

ASP.NET AJAX Autocomplete duplicate selection issue

12 Answers 201 Views
AutoCompleteBox
This is a migrated thread and some comments may be shown as answers.
jagadish
Top achievements
Rank 1
jagadish asked on 15 Jul 2015, 01:25 PM

In autocomplete textbox i am able to select same item multiple times, how can i avoid selecting same item multiple times.

Example:

1. Autocomplete shows list of fruits

2. I will select Apple.

3. Next again i will select apple

 

Now apple is selected 2 times, this is a problem.

How to avoid this?

Please help me in this regard.

Thanks for your cooperation in advance.

 

--

Jagadish Konnur

12 Answers, 1 is accepted

Sort by
0
Aneliya Petkova
Telerik team
answered on 17 Jul 2015, 08:29 AM
Hi Jagadish,

I checked the support ticket that you sent and will also paste the answer here in case anyone else is interested in it:

I would suggest you to use the client-side OnClientEntryAdding event and in its handler to check whether there is an entry with the same text and value in the RadAutoCompleteBox input already. So if there is such entry, you can cancel this event using eventArgs.set_cancel(true); Thus this item will not be added to the entries collection again.

Please check our help articles for additional information:
http://docs.telerik.com/devtools/aspnet-ajax/controls/autocompletebox/client-side-programming/overview

Regards,
Aneliya Petkova
Telerik
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
0
Pierre
Top achievements
Rank 1
answered on 15 Jun 2017, 06:58 AM

"I will also paste the answer here in case anyone else is interested in it"

Where is it ?

0
Sam
Top achievements
Rank 1
answered on 11 Jul 2017, 10:17 AM
function TestMulti(sender, args) {
            var entries = sender.get_entries();
            for (var i = 0; i < entries.get_count() ; i++) {
                if (entries.getEntry(i).get_value() == args.get_entry().get_value()) {
                    args.set_cancel(true);
                }
            }
        }
0
Ciupaz
Top achievements
Rank 2
Veteran
answered on 23 Jun 2020, 05:12 PM

How can I call this TestMulti function?

 

L.

0
Ciupaz
Top achievements
Rank 2
Veteran
answered on 23 Jun 2020, 06:58 PM

I've set here:

 

<telerik:RadAutoCompleteBox RenderMode="Lightweight" runat="server" ID="acbCliente"                   EmptyMessage="Cliente" OnClientEntryAdding = "TestMulti"                    DataTextField="RagSoc" InputType="Token" Width="385" DropDownWidth="150px">                 </telerik:RadAutoCompleteBox>

 

but TestMulti JavaScript function does not work. 

C.

0
Ciupaz
Top achievements
Rank 2
Veteran
answered on 23 Jun 2020, 07:02 PM

An "i" was missing in the JavaScript function.

The correct version in here: 

if (entries.getEntry(i).get_value() == args.get_entry(i).get_value()) {

 

 

0
Yan Moura
Top achievements
Rank 1
Veteran
Iron
answered on 23 Jun 2020, 07:19 PM

I may be wrong but it's not the mission of AutoCompleteBox to get track of your tokens. You have to write your own code to control this.

The best way of doing it is by removing the item from your list once it's picked by the user. Ideally you should push it into an array to keep track of used items to restore them back in case of user delete the token(s).

0
Ciupaz
Top achievements
Rank 2
Veteran
answered on 23 Jun 2020, 08:09 PM

Do you have an example?

My autocompletebox takes data from a DataTable in code-behind.

0
Peter Milchev
Telerik team
answered on 24 Jun 2020, 03:04 PM

Hello L.,

The TestMulti is the name of the function that is used as a client-side event handler of the OnClientEntryAdding event:

That is why the args.get_entry(i) is actually not correct and it should be args.get_entry().

Regarding the items being able to be selected only once, I can recommend using the MultiSelect control instead:

Regards,
Peter Milchev
Progress Telerik

Progress is here for your business, like always. Read more about the measures we are taking to ensure business continuity and help fight the COVID-19 pandemic.
Our thoughts here at Progress are with those affected by the outbreak.
0
Ciupaz
Top achievements
Rank 2
Veteran
answered on 24 Jun 2020, 03:48 PM

Hi Peter,
thank you for your clarification.

But, with RadMultiSelect, if I choose Anne King, is it possible to not show Anne King in dropdownlist below? 

 

0
Peter Milchev
Telerik team
answered on 29 Jun 2020, 08:45 AM

Hello L.,

The easiest way is to hide the selected items with CSS:

<style>
    .RadMultiSelectDropDown .k-item.k-state-selected {
        display: none
    }
</style>

The only downside of this approach is that when navigating through the items in the dropdown with the arrows, the items will still be focused, but due to the fact that the item element itself is hidden, there will be no UI indication what is focused.

Another option is to style the selected item as a disabled one. 

Generally, the items are designed to remain in the dropdown, so that the user can deselect the item by clicking it in the dropdown, not only via the tags.

Regards,
Peter Milchev
Progress Telerik

Progress is here for your business, like always. Read more about the measures we are taking to ensure business continuity and help fight the COVID-19 pandemic.
Our thoughts here at Progress are with those affected by the outbreak.
0
Ciupaz
Top achievements
Rank 2
Veteran
answered on 29 Jun 2020, 09:23 AM

Thank you Peter, this could be a good solution.

Luigi.

Tags
AutoCompleteBox
Asked by
jagadish
Top achievements
Rank 1
Answers by
Aneliya Petkova
Telerik team
Pierre
Top achievements
Rank 1
Sam
Top achievements
Rank 1
Ciupaz
Top achievements
Rank 2
Veteran
Yan Moura
Top achievements
Rank 1
Veteran
Iron
Peter Milchev
Telerik team
Share this question
or