I have the following code snippet and I wanted to show a text on mouse hove of the selected value from the drop down . Currently when I mouse hove the selected value in the text box nothing is showing. I want to show the full text(${dataset.name}-${dataset.description}) when mouse hover. Selected value is only showing the first part(${dataset.name})
In JS
//Setting default configuration here or you can set through configuration object as seen below
$.fn.select2.defaults = $.extend($.fn.select2.defaults, {
allowClear : true, // Adds X image to clear select
closeOnSelect : false, // Only applies to multiple selects. Closes the select upon selection.
placeholder : ‘Select the dataset’,
minimumResultsForSearch : 15, // Removes search when there are 15 or fewer options
formatSelection : customizeSelectedResults
// appearance of selected results can be customized by setting a function to templateSelection configuration option
});
$(document).ready(
function() {
// Single select example if using params obj or configuration seen above
var configParamsObj = {
placeholder : 'Select the dataset',
allowClear : true,// Place holder text to place in the select
minimumResultsForSearch : 3
// Overrides default of 15 set above
};
$("#datasets").select2(configParamsObj);
});
//customizing the appearance of selected results for select2
function customizeSelectedResults(state) {
if (!state) {
return state.text;
}
return state.text.split(' - ')[0];
};
In html
<c:forEach var=“entry” varStatus=“status” items="${datasetMap}">
<c:set var=“dataset” value="${entry.value}" />
<c:set var=“selected” value="" />
<c:forEach var=“item” items="${selectedDataset}">
<c:if test="${item eq dataset.id}">
<c:set var=“selected” value=“selected” />
</c:if>
</c:forEach>
<option value="${dataset.id},${dataset.name},${dataset.description}" ${selected}>
<c:out value="${dataset.name}-${dataset.description}" />
</c:forEach>