2014-04-04 31 views
1

我使用Select2和動態Ajax加載/過濾。Select2 - Textfield而不是下拉框

我想知道的一樣,你可以在「多值選擇框」在這裏看到一個文本框: http://ivaynberg.github.io/select2/

但我得到的是一個下拉。這是我的代碼部分:

= f.input_field :community, :class => :communities 

$(".communities").select2({ 
    allowClear:true, 
    ajax: { 
     ... 
    }, 
    formatResult: formatResult, 
    formatSelection: formatResult 
}); 

我有什麼做的就是一個文本框,而不是一個下拉列表?

回答

1

我認爲createSearchChoice是你需要的功能。

閱讀更多select2搜索createSearchChoice

$(".communities").select2({ 
createSearchChoice(term) 

}); 
+0

這將創建一個下拉列表,以及。除了我不想讓多個值。 –

+0

對不起!已更新的答案 –

+0

但我不希望用戶輸入自由文本,只有假設的結果 –

0

你可以試試這個:

$('.communities').select2({ 
    width: '100%', 
    allowClear: true, 
    multiple: true, 
    ajax: { 
    ... 
    }, 
}); 
相關問題