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

DropDown List Showing items already selected

1 Answer 39 Views
AutoCompleteBox
This is a migrated thread and some comments may be shown as answers.
Ílson
Top achievements
Rank 1
Ílson asked on 29 Oct 2014, 12:14 PM
Hi,

The RadAutoCompleteBox allows me to select items that were already selected.
That way it allows the user to duplicate items selected.

I't happens the same way on that sample http://demos.telerik.com/aspnet-ajax/autocompletebox/examples/default/defaultcs.aspx

When i press 'n' and select Nancy. It goes to the box.
Then i press 'n' and select Nancy again. The i get 2 Nancyes on the box.

Is it expected?
Can i prevent it from showing selected items on the Drop Down?

Thanks in advance.

1 Answer, 1 is accepted

Sort by
0
Nencho
Telerik team
answered on 03 Nov 2014, 09:38 AM
Hello Ílson,

You could prevent the items from displaying in the dropdown, by performing the appropriate query to the underlying datasource and excluding those fields, which matches to the text  of the already added entries. For this purpose, you could use the OnDataSourceSelect event of the RadAutoCompleteBox :

http://www.telerik.com/help/aspnet-ajax/autocompletebox-ondatasourceselect.html

Another approach you could use is to prevent the selection of the certain Item, if an entry with the same text (or value) is already selected. This could be achieved at the OnClientEntryAdding client-side event of the control and by canceling its propagation if a match is found :

<script type="text/javascript">
   
function OnClientEntryAdding (sender, eventArgs) {
    var entries = sender.get_entries(),
    count = entries.get_count();   
                     
    for (var i = 0; i < count; i++) {          
        if(entries.getEntry(i).get_text() == eventArgs.get_entry().get_text())
        {
            eventArgs.set_cancel(true);
        }
    }
}
</script>


Regards,
Nencho
Telerik
 

Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

 
Tags
AutoCompleteBox
Asked by
Ílson
Top achievements
Rank 1
Answers by
Nencho
Telerik team
Share this question
or