Is it possible to enter custom values for the (select) Chosen
Plugin, to create a own value as option?
Asked
Active
Viewed 1,026 times
0

Rory McCrossan
- 331,213
- 40
- 305
- 339

dazzafact
- 2,570
- 3
- 30
- 49
-
If you mean that you want to create a new `option` element in the chosen plugin, see here: http://stackoverflow.com/questions/11352207/jquery-chosen-plugin-add-options-dynamically – Rory McCrossan Sep 04 '14 at 06:42
1 Answers
1
Yes it is possible just call this function onClick and pass custom values in the parameter
function customTags(tagName)
{
var customTagLength = $('li.search-choice').length; //Custom Option length -1 as compare to actual Option length
if(customTagLength>9)
{
return false;
}
// above code to limit select value in chosen
var html = '<option value="'+tagName+'">'+tagName+'</option>';
$('.chosen-select').append(html);
//This is what you need
var SearchChoiceArrayTagName = [tagName];
$('.chosen-select').find('option').filter(function (idx, option) {
if($.inArray(option.value, SearchChoiceArrayTagName) !== -1) {
return option;
}
}).prop('selected', 'true');
$('.chosen-select').trigger("chosen:updated");
$('.chosen-select').chosen().change(function(e, params){
if(params.deselected==tagName)
{
$(".chosen-select option[value='"+tagName+"']").remove();
$(".chosen-select").trigger('chosen:updated');
}
});
}

rocky
- 631
- 5
- 14