select2 - get all option values from input filed

619 views
Skip to first unread message

tsveteli...@gmail.com

unread,
Sep 28, 2015, 6:29:41 AM9/28/15
to select2
Hello,
is it possible when using select2 to get input value not the one from option select.
What I mean is:

<SELECT>
<option> 2010 </OPTION>
<option> 2011 </OPTION>
<option> 2012 </OPTION>
<option> 2013 </OPTION>
<option> 2014 </OPTION>
</SELECT>

When I type "201" I want to send "201" to my ajax function and then search in my database, but when I click enter select2 gets 2010 - the first value from options list.
My configuration is:


$(".clear-results").select2({
placeholder: "Select a State",
allowClear: true,
width: 200,
matcher: function(term, text) {
return zext.trim().toUpperCase().indexOf(term.trim().toUpperCase())==0;
}
});


Regards,
Tsvetelin

tzveteli...@gmail.com

unread,
Sep 29, 2015, 5:52:06 AM9/29/15
to select2, tsveteli...@gmail.com
I found solution:

in select2.js file:

I replaced :
case c.ENTER:return this.selectHighlighted
with
case c.ENTER:return get_input_value(this.search.val())

where get_input_value is my custom ajax function passing dynamically values.

tzveteli...@gmail.com

unread,
Sep 30, 2015, 4:25:27 AM9/30/15
to select2, tsveteli...@gmail.com, tzveteli...@gmail.com
Updated:

case c.ENTER:return get_input_value(this.search.val())

to

case c.ENTER:return get_input_value(this.search.val())
case c.ENTER:return get_input_value(this.search.val(), this.containerId)

Added this.containerId, because select2 can have alot of selects, and we need to know which one send the value.

Reply all
Reply to author
Forward
0 new messages