0

I'm working on a rails app and was trying to integrate this gem for a text field

https://github.com/exAspArk/rails-jquery-tokeninput

However, I get the same console error: ".tokenInput is not a function" as when I try to do this without the gem (manually adding the js and css to the pipeline). I have the gem installed correctly, and this in my _form.html.erb

<% names = [{name: "test", name: "another test name", name: "third name test 123"}] %>
  <%= f.label :user_tokens, "Debaters" %>
  <%= f.text_field :user_tokens, 'data-tokeninput' => {collection: names}.to_json %>

I have properly requires the javascript in my application.js and I do receive token-input.js in the browser so the scripts are loaded properly, but for whatever reason it seems to not recognize the tokenInput function.

Is there something i'm missing with the asset pipeline or loading the proper gems? If someone has experience working with this gem or knows what I'm missing with including the proper javascripts, i'd greatly appreciate any help!

2 Answers 2

1

Your variable names that contains data like array of hash is not properly formatted.

names = [{name: "test", name: "another test name", name: "third name test 123"}]

If you try to parse the above code, it will give you warning like:

duplicated key at line 1 ignored: :name

Because of duplication of key "name".

So, you should properly format it:

names = [{name: "test"}, {name: "another test name"}, {name: "third name test 123"}]

Then, you will have the collection of names.

Like, what @dieuhd said.

Sign up to request clarification or add additional context in comments.

Comments

0

Because you are wrong data of token-collections, it must are:

<% names =  [{name: 'test' }, { name: 'another test name' },{ name: 'third name test 123' }] %>

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.