Kiren S
Kiren S

Reputation: 3097

Getting kendo auto complete on an element that was not already in DOM

I am trying to get a kendo auto complete on a text box that was just appended to the Dom on a button click. Class of the text box is "items", and in document ready I initialized auto complete as

$(".items").kendoAutoComplete({})

Upvotes: 0

Views: 306

Answers (2)

NunoCarmo
NunoCarmo

Reputation: 5509

I usually do it like this.

$("#ButtonSelector").on('click', function() {
    $("<input class='items' />").appendTo($("#Selector"));

    $(".items", this.element).each(function () {
        $(this).kendoAutoComplete({});
    });
});

Upvotes: 0

OnaBai
OnaBai

Reputation: 40887

It should work!

Lets have the following HTML

<a id="button" class="k-button" href="#">Add</a>
<div id="here"></div>

And this is the Javascript

$("#button").on("click", function() {
    $("<div class='items'></div>").appendTo($("#here"));
    $(".items").kendoAutoComplete({});
})

The only problem that I foresee is that using a class for selecting where to add the kendoAutoComplete then you can add only one (otherwise you end up having nested autocompletes).

Upvotes: 1

Related Questions