Skip to content

Instantly share code, notes, and snippets.

@johno
Created May 1, 2014 15:38
Show Gist options
  • Save johno/01eb8c5b5441f54ded41 to your computer and use it in GitHub Desktop.
Save johno/01eb8c5b5441f54ded41 to your computer and use it in GitHub Desktop.
Integrating chosen for tags with the ability to add (the coffeescript portion).
window.chosen_select =
enable: ->
$('.chosen-select').chosen
allow_single_deselect: true
no_results_text: 'No results found'
width: '100%'
add: (select, string) ->
select.prepend($('<option selected="selected">', { value: string })
.text(string))
.trigger('chosen:updated')
$(document).ready ->
chosen_select.enable()
$(document).on 'page:load', ->
chosen_select.enable()
create_tags =
bind_buttons: ->
$('#create_tag').on 'click', ->
$('#tag_wrapper').slideToggle ->
$('#create_tag_wrapper').slideToggle()
$('#cancel_tag').on 'click', ->
$('#tag_text_field').val('')
$('#create_tag_wrapper').slideToggle ->
$('#tag_wrapper').slideToggle()
$('#add_tag').on 'click', ->
chosen_select.add($('#tag_wrapper').find('select'), $('#tag_text_field').val())
$('#tag_text_field').val('')
$('#create_tag_wrapper').slideToggle ->
$('#tag_wrapper').slideToggle()
$(document).ready ->
create_tags.bind_buttons()
$(document).on 'page:load', ->
create_tags.bind_buttons()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment