Tag: jQuery

  • Adding Placeholder attribute to Tokeninput jQuery plugin

    I was having a hard time to get the placeholder attribute to work with Tokeninput jQuery plugin.

    First I managed to get it to show up by adding attr(‘placeholder’) to the onReady:
    $("#myInput").tokenInput("/url/to/your/script/"){
    onReady: function(){ $('#token-input-myInput').attr('placeholder','type here...'); }
    };

    It worked but every time it lost focus the resize of the input field would partially hide it. So, I tweaked with the code inside jquery.tokeninput.js and after line 436 (declaration of var escaped) added:
    if(input_box.attr('placeholder')!=undefined){
    escaped = input_box.attr('placeholder');
    }

    It is not pretty but it works :)