Sha256: ead7c274d79b6fa2710a1e87fce43a4117d42c9cbb2b44f2a8606ce3fe639cd2

Contents?: true

Size: 871 Bytes

Versions: 7

Compression:

Stored size: 871 Bytes

Contents

module TaoForm
  module Components
    class FormComponent < TaoOnRails::Components::Base

      attr_reader :record, :html_options

      def initialize view, record, options = {}
        super view, options
        @record = record
        @html_options = transform_html_options(default_html_options, @options.delete(:html) || {})
      end

      def render &block
        if block_given?
          view.content_tag tag_name, view.simple_form_for(record, options, &block), html_options
        else
          super
        end
      end

      def self.component_name
        :form
      end

      private

      def default_options
        {
          wrapper: view.request.variant.mobile? ? :tao_mobile : :tao_desktop,
          defaults: {tao_form: true}
        }
      end

      def default_html_options
        {class: 'tao-form'}
      end

    end
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
tao_form-1.0.0.beta.2 lib/tao_form/components/form_component.rb
tao_form-1.0.0.beta.1 lib/tao_form/components/form_component.rb
tao_form-0.2.3 lib/tao_form/components/form_component.rb
tao_form-0.2.2 lib/tao_form/components/form_component.rb
tao_form-0.2.1 lib/tao_form/components/form_component.rb
tao_form-0.2.0 lib/tao_form/components/form_component.rb
tao_form-0.1.10 lib/tao_form/components/form_component.rb