I have below HTML code for select2 combobox ( pnlkr link )
<label id="label-select2Home">My Home State: </label>
<div class="select2-home" xe-field="select2Home"></div>
JS to initialize:
$( ".select2-home" ).select2({
tokenSeparators: [",", " "],
allowClear: true,
placeholder: "Select a state",
data: stateData
});
WHAT TO DO
I need to find a shortcut nearby and change the text to "TEST LABEL".
I am trying to do this with
$.fn.select2 = _.wrap($.fn.select2, function changeLabel(org) {
});
I can not do with
// Replace the nearby label text with "TEST LABEL"
var args = Array.prototype.slice.call(arguments, 1); // use Array.slice function to copy the arguments array from 1-end, without 'org'
return org.apply( this, args );
This gives me an error. How to call .apply method to control select2 and change label text.
See plnkr for the above example
source
share