Simple form custom input with acts-as-taggable-on
Asked Answered
E

2

5

I have some problems with Simple_form and acts-as-taggable-on.

I have a object "Pictogram" with some tags like "door" and "emergency"

I use this code in my form

= f.input :tag_list

When I edit my Pictogram the system delete my comma and display my text_field like that "door emergency" if i save my two tags are deleted and replaced by one tag "door emergency"

I'm looking for a solution on the net and many peoples advise to create a custom input in simple_form but I don't where to begin.

I create a file tag_input.rb in app/inputs and I add this code

class TagInput < SimpleForm::Inputs::Base
 def input(wrapper_options)

 end
end

But now I'm lost.

Sorry for my English, it's not my native language

Epistle answered 3/2, 2015 at 13:43 Comment(0)
S
14

Here's what you do based on this

= f.input :tag_list, input_html: {value: @something.tag_list.to_s}
Shackelford answered 11/8, 2015 at 14:53 Comment(2)
This should really be in the README... in fact having usage with forms in general should be in the README!Skied
As suggested edit queue is full, recommend to use: f.input :tag_list, value: f.object.tag_list.join(",")Unschooled
S
1

Custom input contains simple form tags

Check out this wiki https://github.com/plataformatec/simple_form/wiki/Adding-custom-input-components

Inside you can build comma separated string of values

value = object.tags.join(',')
text_field_tag attribute_name, value

Something like that, don't have a simple form nearby, so can't debug this code.

But the main idea I think is clear

Streamer answered 3/2, 2015 at 16:46 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.