I want to add text that the user enters into the text box of the selected selected multiple input as an option, and automatically selects it, all this, when the option does not exist, if the option exists, then I would like to select it. So far I have managed to do this:
Chosen.prototype.add_text_as_option = function () { $('#id_select').append( $('<option>') .html(this.search_field.val()) .attr('selected', 'selected') .attr('value', 0) ); $('#id_select').trigger("liszt:updated"); return false; };
I call this function whenever the user presses the enter button when the input field is in focus in the keydown_check function.
I have two problems:
- Priority, when the user presses the enter button and dials an option substring, the option will not be selected, but the substring text will be added and selected. Not what I want.
For example: if I have the option โfooโ and start typing โfoโ, the selected one will mark the first one (โfooโ), so if I press enter, it should be selected, but instead, it happens that โfoโ is added as option and is selected when I really wanted to select "foo".
If I select "foo" with a click, then everything works fine. The selected option is selected, and the substring text is accepted as part of the option.
How can I add an optional option for selection without losing all the original functions?
How can I access the selected multiple fields that I initialized, selected inside the selected plugin? As you can see in the above code, the identifier of the selected multiple field is hard-coded. I want to do this to update the selection when the user adds a new option.
The functionality I'm looking for is very similar to the linkedin skill widget
Thanks in advance!
danielrvt
source share