Sha256: 368716be7c73e234a1a264c6e26e37f9e6003c9bea94a22fd96bf0937de9037a
Contents?: true
Size: 1.18 KB
Versions: 2
Compression:
Stored size: 1.18 KB
Contents
/* global $, addToList */ $(window).load(function() { if($('#person_tag_chooser').length > 0) { var the_form = $('input[id=person_tags]').parents('form:first'); var initial_tags = $('#person_tags').attr('value'); var tag_list = $('#tag_list').attr('value').split(','); $('.person_tags').remove(); // add a hidden field to store the selected tags $('<input>').attr({ type: 'hidden', id: 'person_tags', name: 'person[tags]', value: initial_tags }).appendTo(the_form); // init the select2 widget $('#person_tag_chooser').select2({ tags: tag_list, width: '480', dropdownCssClass: 'form-control', tokenSeparators: [','], }); // set the default state of the select2 widget $('#person_tag_chooser').select2('val', [initial_tags]); // enable adding a tag with the enter key $('select2-search-field > input.select2-input').on('keyup', function(e) { if(e.keyCode === 13) { addToList($(this).val()); } }); // set the hidden field when the form is submitted the_form.on('submit', function() { $('#person_tags')[0].value = $('#person_tag_chooser').select2('val'); }); } });
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
peoplefinder-0.1.1 | app/assets/javascripts/peoplefinder/tagging.js |
peoplefinder-0.1.0 | app/assets/javascripts/peoplefinder/tagging.js |