Reputation: 3331
I followed this screencast: http://railscasts.com/episodes/258-token-fields?view=asciicast
As one of the steps, I added the prepopulate option as suggested and got the edit form working nicely. This is the javascript, written in coffeescript since I'm using Rails 3.1:
$("#location_token_field").tokenInput "/person/locations.json", {
crossDomain: false,
prePopulate: $(this).data("pre"),
theme: "facebook",
preventDuplicates: true
}
This is all and well except that now, in the #new action, the token input field always starts out with "null" there.
The following is the form part in question:
<div id="location_area">
<%= link_to image_tag("location_icon2.png", :size=>"35x35"), "javascript:void(0)", id: "location_icon", class: "blank_button" %>
<div id="location_field">
<%= f.text_field :location_tokens, id: "location_token_field", placeholder: "Where?",
"data-pre" => memory.locations.map(&:attributes).to_json %>
</div>
</div>
Any ideas why this is happening / how I can solve this? I would like to keep prepopulate so the edit form is populated appropriately.
Upvotes: 0
Views: 728
Reputation: 16472
Just from eying your JavaScript, it looks like you're missing some parentheses:
Try:
$("#location_token_field").tokenInput("/person/locations.json", {
crossDomain: false,
prePopulate: $(this).data("pre"),
theme: "facebook",
preventDuplicates: true
});
and see if that helps.
Upvotes: 1