Avatar of Starr Duskk
Starr Duskk
Flag for United States of America asked on

Setting the Width on a Select2 Placeholder - shows as 0 width

I have two multiple select2 drop down lists on two different pages.

One has a width set for the placeholder, and the other does not when I do an inspect, but I copied the code setup for the first to the second and can't find anywhere that an actual width is being set. The failing one has the width set to 0. The successful one has the width set to 288. But I find 288 no where in my code.

<input class="select2-search__field" type="search" tabindex="0" autocomplete="off" autocorrect="off" autocapitalize="none" spellcheck="false" role="textbox" aria-autocomplete="list" placeholder="[Select]" style="width: 0px;">

Open in new window


both use the exact same method:

$('.ddlSelectMultiple').select2({
placeholder: '[Select]',
allowClear: true,
matcher: function (params, data) {
    return matchStart(params, data);
    },
width: 'resolve',
allowClear: true,
multiple: true,scrollAfterSelect: false,closeOnSelect: false
});

Open in new window


Any ideas where I can find where that width is set? When I create each method, the width is set to 'resolve'

thanks!
JavaScriptjQuery

Avatar of undefined
Last Comment
leakim971

8/22/2022 - Mon
ASKER CERTIFIED SOLUTION
leakim971

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
Starr Duskk

ASKER
I looked at our style and we have it set to 100%

.select2-container {
    width: 100% !important;
}

Open in new window


Do you have any idea why one would translate to 288 and the other to 0?

thanks!
leakim971

using 100% use their respective container width so you did nothing using 100%, 100% of 0 pixel is 0 pixel so you get 0.
Experts Exchange has (a) saved my job multiple times, (b) saved me hours, days, and even weeks of work, and often (c) makes me look like a superhero! This place is MAGIC!
Walt Forbes