JS...">

Select2 4.0 placeholder undefined

Please, help.

HTML:

<select id="select-client" class="form-control" style="width: 350px;"></select>

JS:

$("#select-client").select2({
    ajax: {
        url: _app.url + "finduser",
        dataType: 'json',
        delay: 250,
        data: function (params) {
            return {
                q: params.term
            };
        },
        processResults: function (data) {
            return {
                results: data
            };
        },
        cache: true
    },
    escapeMarkup: function (markup) { return markup; },
    minimumInputLength: 2,
    templateResult: formatClientRepo,
    templateSelection: formatClientRepoSelection,
    placeholder: "Enter user name"
});

And as a result, I got this: http://prntscr.com/76jxvi I found many options, such as an empty option in select or Write placeholder in select , but nothing.

+4
source share
1 answer

https://jsfiddle.net/xqhp0z0x/1/

in this example, if we remove || repo.textfrom formatRepoSelection, this will not work. Because it repo.textis a placeholder.

PS select2 4.0 no need to put a tag optionfor placeholderworking

+3
source

All Articles