Class: Proscenium::UI::Form::Fields::Base

Inherits:
Component
  • Object
show all
Defined in:
lib/proscenium/ui/form/fields/base.rb

Overview

Abstract class to provide basic rendering of an <input>. All field classes inherit this.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(attribute, model, form, type: nil, error: nil, **attributes) ⇒ Base

Returns a new instance of Base.

Parameters:

  • attribute (Array)
  • model (*)
  • form (Proscenium::UI::Form)
  • type (Symbol) (defaults to: nil)

    input type, eg. ‘text’, ‘select’

  • error (ActiveModel::Error, String) (defaults to: nil)

    error message for the attribute.

  • attributes (Hash)

    HTML attributes to pass to the input.



27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/proscenium/ui/form/fields/base.rb', line 27

def initialize(attribute, model, form, type: nil, error: nil, **attributes)
  if attribute.count > 2
    raise ArgumentError, 'attribute cannot be nested more than 2 levels deep'
  end

  @attribute = attribute
  @model = model
  @form = form
  @field_type = type
  @error = error
  @attributes = attributes
end

Instance Attribute Details

#attributeObject (readonly)

Returns the value of attribute attribute.



11
12
13
# File 'lib/proscenium/ui/form/fields/base.rb', line 11

def attribute
  @attribute
end

#attributesObject (readonly)

Returns the value of attribute attributes.



11
12
13
# File 'lib/proscenium/ui/form/fields/base.rb', line 11

def attributes
  @attributes
end

#formObject (readonly)

Returns the value of attribute form.



11
12
13
# File 'lib/proscenium/ui/form/fields/base.rb', line 11

def form
  @form
end

#modelObject (readonly) Also known as: parent_model

Returns the value of attribute model.



11
12
13
# File 'lib/proscenium/ui/form/fields/base.rb', line 11

def model
  @model
end