Created
March 20, 2014 18:16
-
-
Save lsiden/9670311 to your computer and use it in GitHub Desktop.
chnage(ev) always called with ev.data[0] === "initSelection()"
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$('.tags.select2').each -> | |
vocab = $(this).closest('.vocab').data('vocab') | |
opts = { | |
initSelection: (element, callback) -> | |
callback(env.tags[vocab]) | |
multiple: true | |
#allowClear: true | |
placeholder: 'Select one or more' | |
# Load all the terms for this vocab. | |
ajax: { | |
url: env.terms_path | |
dataType: 'json' | |
data: -> | |
{ vocab: vocab } | |
results: (data, pagenum) -> | |
#console.log(data); | |
{ results: data } | |
} | |
tokenSeparators: [',', ';', ' '] | |
} | |
if $(this).hasClass('user-defined') | |
opts.createSearchChoice = (term) -> | |
console.log("createSearchChoice(#{term})") | |
{ id: term, text: term } | |
$(this).select2 opts | |
.change (ev) -> | |
# console.log(ev.val); | |
# There is a bug: ev.val[0] === "initSelection()" | |
if ev.val[0] == "initSelection()" | |
ev.val = ev.val.slice(1) # lopp it off | |
$.ajax env.content_update_tags_path, { | |
method: 'put', | |
data: { | |
tags: { | |
vocab: vocab, | |
terms: ev.val | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment