How to change placeholder of selectize.js dropdown?

后端 未结 10 1386
盖世英雄少女心
盖世英雄少女心 2021-02-14 12:30

I want to change placeholder of a dropdown created by selectize.js when the parent dropdown changes its selection to load the options of the dropdown whose placeholder to be cha

10条回答
  •  醉梦人生
    2021-02-14 13:34

    Not sure if selectize keeps changing their code or if everyone else on this thread just whiffed but all of these answers seem to be wrong individually, but if you kind of combine the correct parts from each answer you wind up with this which works for me.

            var textHandler = function(name) {
            return function() {
                if(name == 'focus'){                    
                    jQuery("select#myid + .selectize-control").find("input:text").prop({"placeholder": ""});
                }
            };
        };
        jQuery('#sf159_textsearchtextsearch').selectize({
            closeAfterSelect: true,
            hideSelected    : true,
            createOnBlur    : true,
            openOnFocus     : true,
            maxOptions      : 10,
            persist         : true,
            placeholder     : "Neighborhood, Street, School, Zip, MLS",
            plugins         : ['remove_button'],
            valueField      : 'id',
            labelField      : 'text',
            searchField     : 'value',
            options         : [],
            create          : false,
            render          : {
                option: function (item, escape) {
                    //console.log(item);
                    var address = '';
                    var keyword = '';
                    var tx = item.text.split(',');
                    for (var i = 0, n = tx.length; i < n; i++) {                        
                        address += '' + escape(tx[i]) + '';                      
                    }
                    var template = '
    ' + '
    ' + address + '
    ' + '
    '; return template; } }, load : searchHandler, onKeydown : keyHandler, onDelete : deleteHandler, onFocus : textHandler('focus'), });

提交回复
热议问题