1

I cannot get the create token or set token to function. Im using following:

$('#myField').tokenfield('createToken', { value: 'violet', label: 'Violet' });
$('#myField').tokenfield('setTokens', ['blue','red','white']);

But its not working. Is there a new way to do it or what can be wrong?

Html:

<div style="width: 400px; margin-left: 20px;">
    <input id="myField" type="text" width="200" />
</div>
Juan
  • 4,910
  • 3
  • 37
  • 46
MikeAlike234
  • 759
  • 2
  • 12
  • 29
  • 1
    Could you include your HTML into the question as well please? Secondly, press F12 on your browser to check for any JavaScript Console errors and state those too. There's nothing in your question that screams like an syntax error, thus probably a script include/conflict error. – MackieeE Mar 07 '14 at 19:11

1 Answers1

2

Having looked through the documentation, it doesn't scream as a pre-requisite! But you'll have have initialise it before calling .tokenfield() functions, as per your code below:

$('#myField').tokenfield('createToken', { value: 'violet', label: 'Violet' });
$('#myField').tokenfield('setTokens', 'blue,red,white');

Demo Fiddle: http://jsfiddle.net/fLjVt/

Add $('#myField').tokenfield(); above the two functions you've added from the docs itself:

/**
 *  Initializes an input with a tokenfield.
**/
$('#myField').tokenfield();

/**
 *  Populate the tokenfield()
**/
$('#myField').tokenfield('createToken', { value: 'violet', label: 'Violet' });
$('#myField').tokenfield('setTokens', 'blue,red,white');

Demo Fiddle: http://jsfiddle.net/myQf7/

MackieeE
  • 11,751
  • 4
  • 39
  • 56