Using html tags options of select2 - jquery-select2

I want to use HTML tags in Select2 options, but when I write that in the normal select box, it doesn't appear in Select2.
<option value="scary">
scary <span>31</span>
<option>
after using select2, the options will appear in the below format
<option value="scary">
scary 31
<option>

Related

Select with dynamic list of options with TeaVM Flavour

I am trying to set up a select dropdown menu, using TeaVM Flavour HTML templates.
While the doc mentions how to do it with a static list of options, it doesn't show how to handle a dynamic list of options.
The trick is to use html:value, which applies both to <input> tags as well as <option> tags:
<select name="mySelect" html:bidir-value="myResult">
<std:foreach var="myOption" in="myList">
<option html:value="myOption">
<html:text value="myOption"/>
</option>
</std:foreach>
</select>

Dojo Select - first option getting selected by default

I have a select box on my form which is getting displayed using addOption. Below the code for the same
storeData = response.myData;
var select = dijit.byId('mySelect');
select.addOption(storeData.items);
HTML declaration of Select box
<select id="mySelect" data-dojo-type="dijit/form/Select" data-dojo-attach-point="mySelect" data-dojo-props="name:'mySelect', placeHolder: 'Select a value', value:''"></select>
In the storeData, I am returning list of JSON objects including a blank option. (label="" and value=" ");
I want the place holder text to get displayed when no option is selected. But by default first option (i.e. blank value option) is getting selected and because of that place holder text is not getting displayed. If I remove the blank value option from list of options, then the option after that is getting selected by default.
Is there any way where I can set the selection to none. Any pointer for this issue?
dijit/form/Select acts as a normal selection box element (simply said it's an enhanced form of <select>). It's the default behavior of such a select box to select the first option by default.
Either way, the dijit/form/Select widget does not support placeholders I think, neither is it documented in the API docs.
As an alternative you could use the dijit/form/ComboBox or dijit/form/FilteringSelect widget, which both support the placeHolder property.
Another common practice (at least with <select>) is that you add a default selected and disabled item, which acts as your placeholder, for example:
<select name="select1" data-dojo-type="dijit/form/Select">
<option disabled="disabled" selected="selected" value="">- Select a state -</option>
<option value="TN">Tennessee</option>
<option value="VA">Virginia</option>
<option value="WA">Washington</option>
<option value="FL">Florida</option>
<option value="CA">California</option>
</select>
Demo: JSFiddle

JQuery multiselect UI how to exclude an option

I am using jQuery UI MultiSelect Widget. I want my list to have 5 options and the first one("Please Choose") to be selected by default, however I want only the last four options as to be visible and selectable from the users when the list is unfolded.Any good idea how to do that?
Thank you
You must have checked the documentation of that plugin, it has everything to customize it in all possible manner. Check out below sample code:
HTML
<select name="gender" id="gender" multiple="multiple">
<option value="MAN">MAN</option>
<option value="WOMAN">WOMAN</option>
</select>
Script
$(document).ready(function(){
$("select").multiselect({
noneSelectedText: 'Choose Options'
});
});
Fiddle

Using custom data attribute in Struts 2 s:select

I'm trying to use custom data attributes of HTML in Struts2 tags
here is my sample code
<s:select list="myList" listKey="myListVal" listValue="myListDesc" data-inputs="myListInput" ></s:select>
i was expecting something like this for example
<select >
<option value="myListVal1" data-inputs="myListInput1">myListDesc1</option>
<option value="myListVal2" data-inputs="myListInput2">myListDesc2</option>
<option value="myListVal3" data-inputs="myListInput3">myListDesc3</option>
</select>
instead I'm getting this
<select data-inputs="myListInput" >
<option value="myListVal1" >myListDesc1</option>
<option value="myListVal2" >myListDesc2</option>
<option value="myListVal3" >myListDesc3</option>
</select>
Is it possible to describe data-attribute in struts select tags for Options inside it.
Override the <s:select> tag template. Or just use HTML tags with <s:iterator>
<select name="list">
<s:iterator value="myList" status="stat">
<option value="<s:property value="myListVal"/>" data-inputs="myListInput<s:property value="#stat.index"/>"><s:property value="myListDesc"/></option>
</s:iterator>
</select>
You can't inject custom attributes into a Struts2 UI Tag directly.
According to Dave Newton's comment, you can with Struts2 >= 2.1.x
But still it's not possible to apply them to the option elements instead of the select, so I'll leave the answer in case you need to extend the original select tag to define a custom behaviour (like apply certain attributes to the options).
You can extend the <s:select> Struts2 tag to allow it to manage new kind of attributes...: http://bodez.wordpress.com/2009/03/13/customising-struts2-jsp-tags/
,
or create your own tag directly, but in your case would be overkill: http://joshuajava.wordpress.com/2008/12/27/creating-custom-components-with-struts-2/).
Last but not least, you could even add your custom attributes once the page is rendered, using something like jQuery (demo: http://jsfiddle.net/CLNDs/ ); they will be accessible, but not visible in source.

Freemarker hash for Struts2 #s.select tag's list property

I'm using Freemarker as the templating engine for a Struts 2 application and having some problems trying to pass a Freemarker hash to the #s.select tag's list value.
Currently I'm trying something like this in my template:
<#s.select name="myDropdown" list={"1":"Foo", "2":"Bar", 3:"Baz"} />
The resulting HTML that's rendered is this:
<select name="myDropdown" id="myDropdown">
<option value="freemarker.ext.beans.HashAdapter$1$1$1#2c9bebb">freemarker.ext.beans.HashAdapter$1$1$1#2c9bebb</option>
<option value="freemarker.ext.beans.HashAdapter$1$1$1#16ca4a">freemarker.ext.beans.HashAdapter$1$1$1#16ca4a</option>
<option value="freemarker.ext.beans.HashAdapter$1$1$1#173ee8">freemarker.ext.beans.HashAdapter$1$1$1#173ee8</option>
</select>
Based on the documentation it seems like this should work, but really the only examples are of using Freemarker lists. Hashes are only mentioned as another option, but I haven't been able to find any code examples that use them.
Ultimately my question is, what Freemarker syntax should I use with the Struts 2 select tag in order to render the following HTML?
<select name="myDropdown" id="myDropdown">
<option value="1">Foo</option>
<option value="2">Bar</option>
<option value="3">Baz</option>
</select>
Using the listKey and listValue properties of the select tag seems to do the trick.
The working code is now:
<#s.select name="myDropdown" list={"1":"Foo", "2":"Bar", 3:"Baz"} listKey="key" listValue="value" />
Seems like that should be taken care of automatically by the tag, but I was not able to get it to work without explicitly setting those two additional properties.

Resources