hack in formtastic input
This commit is contained in:
parent
8118a45953
commit
78b54a1002
|
@ -10,6 +10,10 @@ module Cocoon
|
||||||
# configure our plugin on boot
|
# configure our plugin on boot
|
||||||
initializer "cocoon.initialize" do |app|
|
initializer "cocoon.initialize" do |app|
|
||||||
ActionView::Base.send :include, Cocoon::ViewHelpers
|
ActionView::Base.send :include, Cocoon::ViewHelpers
|
||||||
|
|
||||||
|
if Object.const_defined?("Formtastic") and Formtastic.const_defined?("Inputs")
|
||||||
|
require 'cocoon/formtastic/cocoon_input'
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
|
@ -0,0 +1,24 @@
|
||||||
|
require 'formtastic'
|
||||||
|
|
||||||
|
class CocoonInput
|
||||||
|
include ::Formtastic::Inputs::Base
|
||||||
|
|
||||||
|
def to_html
|
||||||
|
output = []
|
||||||
|
|
||||||
|
output << label_html
|
||||||
|
|
||||||
|
output << builder.semantic_fields_for(method) do |fields|
|
||||||
|
if fields.object
|
||||||
|
template.render :partial => "#{method.to_s.singularize}_fields", :locals => { :f => fields }
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
output << template.content_tag(:div, :class => 'links') do
|
||||||
|
template.link_to_add_association template.t('.add'), builder, method
|
||||||
|
end
|
||||||
|
|
||||||
|
template.content_tag(:li, output.join('').html_safe, :class => 'input cocoon')
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
Loading…
Reference in New Issue