Premium forums

autocomplete against text field but post numerical id with input field

  • Martijn
    Martijn avatar

    16 Jul 2012 (Link to this post)

    I've implemented the autocomplete component successfully to search against a list of website urls. However when I submit my form i want to submit the numerical id value of the site not the text value. Is this possible?

    $("#maintSiteId").kendoAutoComplete({
                    minLength: 3,
                    dataTextField: "site_url",
                    dataValueField: "site_id", // this doesn't seem to work and is depreciated?
                    filter: "contains",
                    height: 320,
                    dataSource: {
                        pageSize: 20,
                        transport: {
                            read: {
                                url: "/Sites/DataJsonSites.cshtml",
                                dataType: "json",
                                type: "GET"
                            },
                            parameterMap: function(options) {
                                return $.extend(options, {
                                    id: '',
                                    title: $("#maintSiteId").data("kendoAutoComplete").value()
                                });
                            }
                    },
                    placeholder: "Select site...",
                    separator: ", ",
                    suggest: true
                    }
                });

    Input field contained within standard <form>
    <input class="span6" id="maintSiteId" name="maintSiteId" style="width: 320px; margin-left: 0;"/>

    Sample JSON data being used;
    [{"site_id":1,"site_url":"www.mysite1.com","site_name":"my site 1"},{"site_id":2,"site_url":"www.mysite2.com","site_name":"my site 2"}] 

Read FAQ or see Kendo UI in action!

Launch Demos