0
我正在使用Select2向其他用戶(多個標籤)分配內容。這一切都很好,除了我不知道如何刪除一旦添加的受讓人。Select2不會從令牌列表中刪除ID
一次,我已經將用戶添加到我的模式受讓人名單,之後我點擊十字select2-search-choice-close
類,用類select2-search-choice
從輸入字段刪除,但ID不會從受讓人刪除相應的列表項令牌(並在我提交表單時傳遞給控制器)。
我錯過了什麼?
注意:我不是100%確定這是否相關,但我注意到,提交表單時通過的assignee_ids有時包含相同的id幾次(例如:assignee_ids =>「12,1,4,4 「)。
這是我的初始化輸入:
$('#assignable_item_assignment_assignee_ids').select2({
minimumInputLength: 2
tags: true
tokenSeparators:[',', ' ']
createSearchChoice: (term, data) ->
{id: term, new_choice: true}
multiple: true
ajax:
url: url
dataType: 'json'
quietMillis: 150
data: (term, page) ->
query: term
results: (data, page) ->
return {results: data}
formatResult: userFormatResult
formatSelection: userFormatSelection
formatInputTooShort: (term, minLength) ->
"Search existing users or assign by email"
dropdownCssClass: 'select2'
})
這是我使用的形式:
<%= form_for AssignableItemAssignment.new, url: assignable_items_assignments_path, html: { class: "form-horizontal", id: "new-assignment" } do |f| -%>
<fieldset>
<div class="control-group">
<%= f.label :to %>
<div class="with-spinner">
<%= f.text_field :assignee_ids, placeholder: "Search users by name or email", class: 'select2' %>
</div>
</div>
<div class="control-group">
<%= f.label :add_a_message %>
<%= f.text_area :message, rows: 3, placeholder: "Add a message for your recipients (optional)" %>
</div>
<%= f.button "Submit", disable_with: 'Submiting' %>
</fieldset>
<% end %>