rails selectize.js include_blank or autocomplete: false

456 views Asked by At

Problem: when I enter the client/_form.haml, a group is autoselected by selectize.js, whereas I want the field to be blank by default, unless I start typing or enter the dropdown.

I am using the gem "selectize-rails".

Student has many Groups.

Main.js:

/*global $*/
/*global app*/
$(document).ready(function(){
    if ($('.selectize')){
        $('.selectize').selectize({
            sortField: 'text'
        });
    }

});

student/_form.haml:

= simple_form_for(@client_group) do |f|
  .form-inputs
    = f.input :client_name
    = f.select :group_id, Group.all.map{|c| [c, c.id]}, {},class: 'selectize'
  .form-actions
    = f.button :submit, class: 'btn btn-primary'
1

There are 1 answers

0
Yshmarov On BEST ANSWER

Adding include_blank: true fixes the problem:

= f.select :group_id, Group.all.map{|c| [c, c.id]}, {include_blank: true},class: 'selectize'