Sha256: 7c12307098820647a068cdba1b623b19938886fbfbf55508d850af2618288b62

Contents?: true

Size: 1.39 KB

Versions: 17

Compression:

Stored size: 1.39 KB

Contents

module Eac
  module CommonFormHelper
    class FormBuilder
      module FieldsFor
        def fields_for(association, &block)
          fieldset(association) do
            nested_fields(association, &block) << add_link(association)
          end
        end

        private

        def nested_fields(association, &block)
          form.nested_fields_for(association) do |nested_form|
            helper.content_tag(:div, class: 'nested_form_row') do
              helper.capture(FormBuilder.new(nested_form, helper), &block) <<
                remove_link(nested_form)
            end
          end
        end

        def add_link(association)
          form.add_nested_fields_link(association, 'Adicionar', class: 'btn btn-primary',
                                                                role: 'button')
        end

        def remove_link(nested_form)
          nested_form.remove_nested_fields_link('Remover', class: 'btn btn-danger',
                                                           role: 'button')
        end

        def fieldset(association, &block)
          helper.content_tag(:fieldset, class: 'nested_form') do
            helper.content_tag(:legend, fieldset_legend(association)) << block.call
          end
        end

        def fieldset_legend(association)
          I18n.t("helpers.label.#{form.object.class.name.underscore}.#{association}")
        end
      end
    end
  end
end

Version data entries

17 entries across 17 versions & 1 rubygems

Version Path
eac_rails_utils-0.8.0 lib/eac/common_form_helper/form_builder/fields_for.rb
eac_rails_utils-0.7.1 lib/eac/common_form_helper/form_builder/fields_for.rb
eac_rails_utils-0.7.0 lib/eac/common_form_helper/form_builder/fields_for.rb
eac_rails_utils-0.6.0 lib/eac/common_form_helper/form_builder/fields_for.rb
eac_rails_utils-0.5.0 lib/eac/common_form_helper/form_builder/fields_for.rb
eac_rails_utils-0.4.0 lib/eac/common_form_helper/form_builder/fields_for.rb
eac_rails_utils-0.3.0 lib/eac/common_form_helper/form_builder/fields_for.rb
eac_rails_utils-0.2.2 lib/eac/common_form_helper/form_builder/fields_for.rb
eac_rails_utils-0.2.1 lib/eac/common_form_helper/form_builder/fields_for.rb
eac_rails_utils-0.2.0 lib/eac/common_form_helper/form_builder/fields_for.rb
eac_rails_utils-0.1.15 lib/eac/common_form_helper/form_builder/fields_for.rb
eac_rails_utils-0.1.14 lib/eac/common_form_helper/form_builder/fields_for.rb
eac_rails_utils-0.1.13 lib/eac/common_form_helper/form_builder/fields_for.rb
eac_rails_utils-0.1.12 lib/eac/common_form_helper/form_builder/fields_for.rb
eac_rails_utils-0.1.11 lib/eac/common_form_helper/form_builder/fields_for.rb
eac_rails_utils-0.1.10 lib/eac/common_form_helper/form_builder/fields_for.rb
eac_rails_utils-0.0.1 lib/eac/common_form_helper/form_builder/fields_for.rb