1

I've been wondering how to get id's to post from Bootstrap Tokenfield.

I've build the following jsfiddle:http://goo.gl/MiQajX

var friends = new Bloodhound({
    datumTokenizer: Bloodhound.tokenizers.obj.whitespace('name'),
    queryTokenizer: Bloodhound.tokenizers.whitespace,
    prefetch: {
        url: 'https://gist.githubusercontent.com/tbbooher/806c767e1fb1f4177e61/raw/375f05ce0b3a771198c9addd98ae0352d5f4b7bb/json.json'
    }
});

friends.initialize();

 $('#journal_entry_friend_ids').tokenfield({
    typeahead: [
    null, {
    displayKey: 'name',
    source: friends.ttAdapter()
    }]
 })

with the goal of getting twitter typeahead and bootstrap tokenfields to work together. The problem is that when I post, the values submitted are a comma-separated list of token lables, not the id values of the tokens.

The ideal functionality would be to POST the input tag value as a string of ids: i.e. "1,3,7,12". Also, when the page loads with a string in the input field, tokenfield would automatically populate the input field (so that the page could be edited).

Since this is very basic behavior, I'm sure other users have figured this out. Any help is appreciated, particularly in figuring out the internals of how this code interacts with the DOM.

bonhoffer
  • 1,421
  • 2
  • 23
  • 38
  • It turns out the value/label feature built in just allows for a different label to display to the user than the underlying value that is searched on or submitted to $_POST – bonhoffer Sep 07 '15 at 11:19

0 Answers0