Select2 is duplicating my dropdown list

时光怂恿深爱的人放手 提交于 2019-12-12 12:32:36

问题


Select2 is duplicating my dropdown list so I have both the original select list and also the select2 select box, I have been unable to recreate it outside of my project so it could be an import perhaps, has anybody experienced anything similar before or know what imports could be causing it? The only information I could find was on jquery growfield which I do not have. Thanks!

HTML

<p class="form-control input-lg"><label for="industry">Industry</label>:
    <select class="industry" id="industry" name="industry">
        <option value="Select" selected="selected"></option>
        {% for industry in industries %}
            <option value="{{ industry }}">{{ industry }}</option>
        {% endfor %}
    </select>
</p>

JQuery

 <script type="text/javascript">
     $(document).ready(function () {
     $("#industry").select2();
     $
 });

回答1:


I found out that the issue was caused by my use of css on the original list element.
Select2 works by applying the class select2-hidden-accessible to the actual select field I wrote.

That class has CSS that, among other things, shrinks the original select field to 1px width so it is not visible.
Then it renders its own span classes that have the select2 functionality based on the content from the original select element.

CSS on .form_inputs select{} was overriding this shrinking to 1px width.



来源:https://stackoverflow.com/questions/31794592/select2-is-duplicating-my-dropdown-list

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!