Add jquery autocomplete on ready to multiple text inputs

Posted by marcinn on Stack Overflow See other posts from Stack Overflow or by marcinn
Published on 2010-05-10T13:27:07Z Indexed on 2010/05/10 13:34 UTC
Read the original article Hit count: 391

Filed under:
|
|
|

Hi,

I have problem in adding autocomplete plugin to multiple text inputs in loop (no errors are returned).

// get text inputs to attach autocomplete    
var locinputs = $('#localizations').find('input:text');

// iterate over elements and add autocomplete plugin
        for (var i = 0; i < locinputs.length; i++) {
           // asp.mvc array with special characters replacing 
            var locNameField = locinputs[i].name.replace('[', '\\\\[');
            locNameField = locNameField.replace(']', '\\\\]');
            locNameField = locNameField.replace('.', '\\\\.');

            $('input#' + locNameField).autocomplete('<%=Url.Action("GetCity", "Localization") %>', {
                extraParams: {
                    provinceId: function () { return 21; }
                },
                dataType: 'json',
                parse: function (data) {
                    var rows = new Array();
                    for (var i = 0; i < data.length; i++) {
                        rows[i] = { data: data[i], value: data[i].PlaceId, result: data[i].Name };
                    }
                    return rows;
                },
                formatItem: function (row, i, n) {
                    return row.Name;
                },
                width: 300,
                mustMatch: true,
                multiple: true
            });
        }

There is no error on loading, I tried to debug using Firebug, elements are accessible by jquery selector

© Stack Overflow or respective owner

Related posts about jQuery

Related posts about autocomplete