submitting select2 form with jquery upon single select dropdown -


i have single select dropdown. when user makes selection, want form submited jquery.

my jquery code follows:

$(document).on('page:change', function(){    function matchstart(params, data) {       params.term = params.term || '';       if (data.text.touppercase().indexof(params.term.touppercase()) == 0) {           return data;       }       return false;   }    $("select#user_country").select2({     matcher: function(params, data) {         return matchstart(params, data);     },     placeholder: "select country",   })    $("select#user_country").on('select2:select', function (event) {      return ('form#selectcountry').submit();   });  }); 

rails view:

<%= form_tag users_path, method: :get, id: 'selectcountry' |f| %>   <%= select_tag "country", options_from_collection_for_select(iso3166::country.countries.sort_by(&:name), 'un_locode', 'name'), :include_blank => true %>   <%= submit_tag "search", :name => "nil", :id => "submit-me" %> <% end %> 

link here 'select2:select' documentation

$('select').on('select2:select', function (evt) {   // }); 

edit

i forgot mention event listener works, have tested alert message, not submitting form.

$('select#country').on('select2:select', function () {   $('input#submit-me').trigger('click'); }); 

couldn't form submit did this.


Comments