Muatik Muatik - 1 year ago 174
Javascript Question

capturing enter key in select2

I'm using select2 to present an editable selectbox. When user writes a statement which does not appear in the

list(select2, data)
, I show a button to add this statement to the list.

Forcing users to click the button seems to me a little bit frustration. Is it possible to capture enter key in select2? I want to make user able to add his/her new statements into the list just by pressing enter key.

Answer Source
$('select2-search-field > input.select2-input').on('keyup', function(e) {
   if(e.keyCode === 13) 
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download