Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Select2 Placeholder Issue

I have a Select2 Multiselect html element. While rendering the placeholder is not displaying, but if I select and remove the item, the placeholder is displaying. I have no idea how to make it work. Please advise.

Initially

enter image description here

While Selection

enter image description here

After removing the items

enter image description here

enter image description here

Code:

@Html.DropDownListFor(m => m.Vendor, new SelectList(Model.Status), "Search Status", new { @id = "advanced-search-lsc-status", @class = "form-control", @multiple = "multiple", data_placeholder = "Select Status" })


$('#advanced-search-status').select2({
            minimumResultsForSearch: -1,
            placeholder: function(){
                $(this).data('placeholder');
            },
            width: '100%'
        });
like image 521
Ranjith Varatharajan Avatar asked Oct 24 '25 23:10

Ranjith Varatharajan


1 Answers

Just now found out that what was wrong, initially the width was set to 0 which hides the placeholder.

enter image description here

Just manipulated using this jquery code.

.select2-container--default .select2-search--inline .select2-search__field{
    width:initial!important;
}

now it works

enter image description here

Thanks guys.

like image 118
Ranjith Varatharajan Avatar answered Oct 27 '25 14:10

Ranjith Varatharajan



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!