简体   繁体   中英

How can I remove Materialize's select dropdown when using select2?

I use both MaterializeCSS and Select2, and have a normal :

<label>Seleção de PFJ</label>
<select id="manual-download-pfj-select" name="pfj-select" multiple></select>

And then:

$("#manual-download-pfj-select").select2({width: "100%"});

All ok except for one problem:

在此处输入图片说明

I get this annoying dropdown repetition (Which is the default one from MaterializeCSS, but it has no search function, so I want to just remove it). I've seen libraries to combine MaterializeCSS and Select2, but they're useless since they only change the colours / theme, keeping the useless repetition. Either one, or the other, with the search function.

I've managed to do it by removing the visilibity of the select-wrapper directly:

.select-wrapper {
    display: none !important;
}

Which is far from ideal, but it seems to be the only way. Now I can use those .css adaptations to make Select2 look like MaterializeCSS.

I would use the browser-default class, which tell the framework to skip the element:

<div class="row">
  <label class="">Seleção de PFJ</label>
    <select class="browser-default" multiple>
      <option value="1">example 1</option>
      <option value="2">example 2</option>
      <option value="3">example 3</option>
    </select>
</div>

This will keep the search functionality of Select2 :

在此处输入图片说明

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM