Recommend this page to a friend! |
Classes of fathurrahman | mnTemplate | public/asset/vendor/select2/docs/pages/08.selections/docs.md | Download |
|
![]() title: Selections taxonomy:
process:
never_cache_twig: trueWhen an option is selected from the dropdown menu, Select2 will display the selected value in the container box. By default, it will display the TemplatingThe appearance of selected results can be customized by using the <div class="s2-example">
</div> <pre data-fill-from=".js-code-example-templating"></pre> <script type="text/javascript" class="js-code-example-templating"> function formatState (state) { if (!state.id) {
} var baseUrl = "{{ url('user://pages/images/flags') }}"; var $state = $(
); // Use .text() instead of HTML string concatenation to avoid script injection issues $state.find("span").text(state.text); $state.find("img").attr("src", baseUrl + "/" + state.element.value.toLowerCase() + ".png"); return $state; }; $(".js-example-templating").select2({ templateSelection: formatState }); </script> >>> You may find it helpful to use a client-side templating engine like Handlebars to define your templates. Built-in escapingBy default, strings returned by If you need to render HTML with your selection template, you must wrap your rendered selection in a jQuery object. In this case, the selection will be passed directly to >>>> Anything rendered as a selection is templated. This includes placeholders and pre-existing selections that are displayed, so you must ensure that your templating functions can support them. Limiting the number of selectionsSelect2 multi-value select boxes can set restrictions regarding the maximum number of options that can be selected. The select below is declared with the <div class="s2-example">
</div> <pre data-fill-from=".js-code-placeholder"></pre> <script type="text/javascript" class="js-code-placeholder"> $(".js-example-basic-multiple-limit").select2({ maximumSelectionLength: 2 }); </script> Clearable selectionsWhen set to
|