简体   繁体   English

如何使用多个引导选择显示所有选定的选项?

[英]How to display all selected options using multiple bootstrap-select?

I am using silviomoreto bootstrap-select.我正在使用 silviomoreto bootstrap-select。 Here is the link with documentation http://silviomoreto.github.io/bootstrap-select/ On few select options I am using multiple select and i have next problem.这是文档的链接http://silviomoreto.github.io/bootstrap-select/在几个选择选项上,我使用了多选,我有下一个问题。

If there is more options selected, they don't fit into select input.如果选择了更多选项,则它们不适合选择输入。 Like this ( screenshot example ) .像这样(截图示例)。 Is there any way that with every new selected option that input box expands the height and display everything that user selected?有什么办法可以让输入框的每个新选择选项扩展高度并显示用户选择的所有内容? Also i tried to change css我也试图改变 css

.bootstrap-select.btn-group .btn .filter-option {
   display: inline-block;
   width: 100%;
   float: left;
   text-align: left;
   color: #333 !important;
   text-transform: uppercase;
   overflow: visible;
   height: 150px;
}

but that didn't work neither.但这也不起作用。

Thanks in advance!提前致谢!

You must add this line to css of .btn: white-space: normal;您必须将此行添加到 .btn 的 css: white-space: normal;

.bootstrap-select .btn {
    white-space: normal;
}

Then you must set the correct initial width, padding and stuff.然后你必须设置正确的初始宽度、填充和东西。 Hope this works.希望这有效。

None of the solutions on this page worked for me.此页面上的所有解决方案都不适合我。 I ended up writing some jQuery code to take care of it.我最终编写了一些 jQuery 代码来处理它。 Here is it, in case it helps anyone else!这是它,以防它对其他人有帮助!

 $(document).ready(function(){ $('#my_select').on('loaded.bs.select hidden.bs.select', function(){ $(this).parent('.bootstrap-select').css('height','auto'); $(this).next('.btn').css('overflow','hidden').height($(this).next('.btn').find('.filter-option-inner').height()); }); });
 <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous"> <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap-theme.min.css" integrity="sha384-rHyoN1iRsVXV4nD0JutlnGaslCJuC7uwjduW9SVrLvRYooPp2bWYgmgJQIXwl/Sp" crossorigin="anonymous"> <link href="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-select/1.13.5/css/bootstrap-select.min.css" rel="stylesheet"/> <script src="https://code.jquery.com/jquery-1.12.4.min.js" integrity="sha384-nvAa0+6Qg9clwYCGGPpDQLVpLNn0fRaROjHqs13t4Ggj3Ez50XnGQqc/r8MhnRDZ" crossorigin="anonymous"></script> <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js" integrity="sha384-Tc5IQib027qvyjSMfHjOMaLkfuWVxZxUPnCJA7l2mCWNIpG9mGCD8wGNIcPD7Txa" crossorigin="anonymous"></script> <script src="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-select/1.13.5/js/bootstrap-select.js"></script> <select id="my_select" class="form-control selectpicker" multiple data-multiple-separator="<br>"> <option>Value 1</option> <option>Value 2</option> <option>Value 3</option> <option>Value 4</option> <option>Value 5</option> </select>

With the result being:结果是:

Multiple Selected Options Shown显示多个选定选项

I think you want to use the multi select instead of the select.我认为您想使用多选而不是选择。

   <select class="selectpicker" multiple title='Choose one of the following...'>
         <option>Mustard</option>
          <option>Ketchup</option>
          <option>Relish</option>
      </select>

And if you want the width of your select box to grow with the selections, you could set a dynamic width accordingly to the div.bootstrap-select class.如果您希望选择框的宽度随着选择而增长,您可以根据 div.bootstrap-select 类设置动态宽度。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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