1

I am using jQuery Tokeninput and works perfectly. I let user select category from the Tokeninput box. Now, I need to put a button which will open a popup screen and it will let user to insert a new category to Database. After user inserts the new category, popup will close and I want that new category be in the Tokeninput box as a token.

here is my code,

<script type="text/javascript">
$(document).ready(function () {
    $("#demo-input-facebook-theme").tokenInput("http://iyihekim.com/MedBulCategory_Service.aspx", {

        onAdd: function (item) {
            $.cookie("Kat_" + item.name, item.id);
        },
        onDelete: function (item) {
            var date = new Date();
            date.setTime(date.getTime());
            $.cookie("Kat_" + item.name, item.id, { expires: date });
        },

        theme: "facebook"

    });
});

I know that if I add prepopulate function as below, It will create it on Load but I want to call that function after popup box closes

<script type="text/javascript">
$(document).ready(function () {
    $("#demo-input-facebook-theme").tokenInput("http://iyihekim.com/MedBulCategory_Service.aspx", {
         // added this***************************
        prePopulate: [
            {id: 123, name: "Slurms MacKenzie"},
            {id: 555, name: "Bob Hoskins"},
            { id: 9000, name: "Kriss Akabusi" }],

        onAdd: function (item) {
            $.cookie("Kat_" + item.name, item.id);
        },
        onDelete: function (item) {
            var date = new Date();
            date.setTime(date.getTime());
            $.cookie("Kat_" + item.name, item.id, { expires: date });
        },

        theme: "facebook"

    });
});

Please help

4

1 回答 1

1

这听起来像是你可以使用“add”事件来做的事情。

$("#demo-input-facebook-theme").tokenInput("add", {id: x, name: y})
于 2013-07-08T12:39:24.357 回答