Adding new values to chosen plugin (Multiple chosen select box )

Adding new values in chosen select box if value is not exists in a list .Chosen is a jQuery Plugin, which gives some likely looking multiple selects in your html form.

In the source code (chosen.jquery.js) Go to case 13 (13 is the keycode for ‘Enter’) option in the switch block
if (this.results_showing) {
return this.result_select(evt);
}

Add following code here
$(this.form_field).append('' + $(evt.target).val() + '');
$(this.form_field).trigger('chosen:updated');
this.result_highlight = this.search_results.find('li.active-result').last();
return this.result_select(evt);

and your final code looks like this :
case 13:
evt.preventDefault();
if (this.results_showing) {
if (!this.is_multiple || this.result_highlight) {
return this.result_select(evt);
}
$(this.form_field).append('' + $(evt.target).val() + '');
$(this.form_field).trigger('chosen:updated');
this.result_highlight = this.search_results.find('li.active-result').last();
return this.result_select(evt);
}
break;

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s