2016-12-18 75 views
0

問題:當我輸入客戶端/ _form.haml時,一個組被selectize.js自動選中,而我希望該字段默認爲空,除非我開始鍵入或者進入下拉菜單。我正在使用gem "selectize-rails"rails selectize.js include_blank或自動完成:false

學生有很多組。

Main.js:

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

}); 

學生/ _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

添加include_blank: true解決了這個問題:

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