Select2: Tags: Different Text for selected Tags -


how can have different text when element selected displayed yet.

enter image description here

background: text display in option pretty long, want show shorter version, when slected.

you can use templateselection option of select2 custom attribute option tag

html:

<select id="long" class="js-example-basic-multiple" multiple="multiple">         <option data-custom="" value="all">all </option>         <option data-custom="lorem ipsum" value="#ff0000">lorem ipsum dolor sit amet consectetur adipiscing elit</option>         <option data-custom="sed do" value="#00ff00">sed eiusmod tempor incididunt ut labore et dolore magna aliqua</option>         <option data-custom="ut enim" value="#0000ff">ut enim ad minim veniam quis nostrud exercitation</option>         <option data-custom="duis aute" value="#ffff00">duis aute irure dolor in reprehenderit in voluptate velit esse</option>     </select> 

javascript:

jquery(function() {             jquery('#long').select2({                 templateselection: function (selection) {                     return jquery(selection.element).data('custom');                 }             });         }); 

https://jsfiddle.net/rijokpaul/phz9e5cs/4/


Comments

Popular posts from this blog

javascript - Create a stacked percentage column -

Optimising Firebase database by automatically overwriting data -

javascript - Angular UI-Grid customTemplate directive causing rows to load slowly/? -