Search code examples
jqueryjquery-dropkick

Disable an item using a dropkick


Can someone help me with writing a sample code of how to disable an item in such a way so that the user cannot select it

I read the documentation from http://dropkickjs.com/docs/#Dropkick#disabled.

They only have for JavaScript and not for jQuery.

Any assistance is a great help.


Solution

  • I have resolved this issue.

    Basically this is just a hack.

    First when the user clicks on the dropdown list, the color of the option that you want to disable has to be grey so the user can know that the option is disabled.

    Therefore, I implemented this jQuery:

       $(".dk_container").on("click", function () {
                $(this).find(".dk_options").find("li").each(function () {
                    var value = $(this).find("a").attr("data-dk-dropdown-value");
                    //The item you want to change the color
                    if (value == "1") {
                        $(this).find("a").css("background", "grey");
                    }
                });
            });
    

    Once that is done, the next step is to disable that option when clicked. I implemented the following jQuery:

        $(".dk_container").find(".dk_options a").off("click");
                $(".dk_container").find(".dk_options a").on("click", function () {
                    //The item you want to disable
                   if ($(this).attr("data-dk-dropdown-value") == "1") { return false; }
    
            });