Last active
August 29, 2015 14:16
-
-
Save kivanio/1c3a6b5ec8cd80642df1 to your computer and use it in GitHub Desktop.
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
@import "select2"; |
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
#= require active_admin/base | |
#= require select2 | |
$(document).ready -> | |
$(".tagselect").each -> | |
$this = $ this | |
placeholder = $this.data 'placeholder' | |
url = $this.data 'url' | |
saved = $this.data 'saved' | |
$this.select2 | |
tags: true | |
width: 'element' | |
placeholder: placeholder | |
minimumInputLength: 2 | |
initSelection: (element, callback) -> | |
saved and callback(saved) | |
ajax: | |
url: url | |
dataType: 'json' | |
data: (term) -> | |
q: term | |
results: (data) -> | |
results: data | |
createSearchChoice: (term, data) -> | |
f = $(data).filter -> | |
@name.localeCompare(term) is 0 | |
if f.length is 0 | |
id: term | |
name: term | |
formatResult: (item) -> | |
item.name | |
formatSelection: (item) -> | |
item.name |
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
ActiveAdmin.register Photo do | |
permit_params :tag_list | |
form multipart: true do |f| | |
f.inputs do | |
f.input :tag_list, | |
label: 'Tags', | |
input_html: { | |
data: { | |
placeholder: 'Enter tags', | |
saved: f.object.tags.map{ |t| { id: t.name, name: t.name } }.to_json, | |
url: auto_complete_tags_path | |
}, | |
class: 'tagselect' | |
} | |
end | |
f.actions | |
end | |
end |
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
json.array!(@tags) do |tag| | |
json.extract! tag, :name | |
json.id tag.name | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment