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

Force Input To Be Part of Data Set With AutoComplete

1 Answer 258 Views
AutoComplete
This is a migrated thread and some comments may be shown as answers.
Russell Solberg
Top achievements
Rank 1
Russell Solberg asked on 13 Apr 2012, 05:07 PM
I have a list of codes that I'd like a user to be able to input into a textbox.  The list of codes will be separated by a comma so they can input n+1.  But I don't want the user to be able to enter a code that isn't in the dataset.  As of right now I have a hard coded data array, but the plan is to use an ASMX web service that returns filtered data based upon what the user has typed.

var data = [
                "M10A",
                "M11A",
                "M12A",
                "M15A",
                "M15B",
                "M15C",
                "M15D",
                "M16A"
            ];
 
//create AutoComplete UI component
$("#<%= txtMailCodes.ClientID %>").kendoAutoComplete({
    dataSource: data,
    filter: "startswith",
    placeholder: "Mailing Codes...",
    separator: ", "
});

I assume I could do something with functions for on input or something along those lines to validate the entry, but I'm hoping there is a property for this.

1 Answer, 1 is accepted

Sort by
0
Georgi Krustev
Telerik team
answered on 17 Apr 2012, 03:08 PM
Hello Russell,

 
The AutoComplete widget allows any user input and only provides suggestion based on the typed letters. If you need to prevent custom values then you need to validate the input manually. One possible solution is to track the select event ( it is raised only when an item is clicked) and in the change event to determine whether the new value is valid or not.

Kind regards,
Georgi Krustev
the Telerik team
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
Tags
AutoComplete
Asked by
Russell Solberg
Top achievements
Rank 1
Answers by
Georgi Krustev
Telerik team
Share this question
or