tsechingho / chosen-rails

Integrate Chosen javascript library with Rails asset pipeline
https://github.com/tsechingho/chosen-rails
MIT License
524 stars 233 forks source link

Does not work with onchange: 'this.form.submit() #113

Open yshmarov opened 3 years ago

yshmarov commented 3 years ago

My code: = select_tag :movie_id, options_for_select(Movie.map{|c| [c.to_s, c.id]}), { onchange: 'this.form.submit()', class: 'chosen-select' }

Expected behaviour: having added onchange: 'this.form.submit()', whenever a value is selected the form gets submitted.

Current behaviour: does not work with onchange: 'this.form.submit()'

yshmarov commented 3 years ago

actually, adding onchange: 'this.form.submit()' to the javascript kind of helps:

(function() {
  $(function() {
    return $('.chosen-select').chosen({
      onchange: 'this.form.submit()',
      allow_single_deselect: true,
      no_results_text: 'No results matched',
      width: '200px'
    });
  });

}).call(this);
buncis commented 2 years ago

what is ur rails version? did using this.form.requestSubmit() helps?

kashiftufail commented 1 year ago

In Rail 7

  <%= f.select :city, ["Berlin", "Chicago", "Madrid"] , {include_blank: "none"} ,onchange: "this.form.requestSubmit()" %>

  <%= f.collection_select :user_id, User.all,:id,:email,{include_blank: "none"} , {onchange: "this.form.requestSubmit()"} %>