Search code examples
javascriptjqueryruby-on-railsajaxbootstrap-select

Bootstrap select turns from dropdown into input field on AJAX - js.erb


Having a small issue - when I am trying to update the view results via AJAX in Ruby on Rails (js.erb) ie. when I update/render the form via AJAX, selectpicker turns into just simple input, hence it just disappears from the view. Could someone suggest what I need to do to fix that?

= form.input_field :id, :include_blank => "Some text...", collection: @some_ids, 
class: 'selectpicker', "data-style" => "btn", 
"data-width" => "100%", :selected => object.id, :id => "some_id"

Solution

  • You likely need to rebind if the select is dynamically added to the page. You should add:

    $('.selectpicker').selectpicker();
    

    to your js.erb file after the content is added to the DOM to initialize elements with the selectpicker class as select pickers.