Class: StimulusPlumbers::Form::Field

Inherits:
Base
  • Object
show all
Defined in:
lib/stimulus_plumbers/form/field.rb

Constant Summary collapse

TYPES =
%i[
  text email number url tel color month week range datetime_local
  text_area file password date time select search
].freeze
COLLECTION_TYPES =
%i[radio check_box collection_select grouped_collection_select].freeze
FLOATING_TYPES =
%i[standard filled outlined].freeze
OPTIONS =
(Base::OPTIONS + %i[hide_label]).freeze

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Base

#described_by, #error?, #render_errors, #render_hint, #theme

Constructor Details

#initialize(template, hide_label: false, **kwargs) ⇒ Field

Returns a new instance of Field.



22
23
24
25
# File 'lib/stimulus_plumbers/form/field.rb', line 22

def initialize(template, hide_label: false, **kwargs)
  super(template, **kwargs)
  @hide_label = hide_label
end

Instance Attribute Details

#hide_labelObject (readonly)

Returns the value of attribute hide_label.



16
17
18
# File 'lib/stimulus_plumbers/form/field.rb', line 16

def hide_label
  @hide_label
end

Class Method Details

.label_id(input_id) ⇒ Object



18
19
20
# File 'lib/stimulus_plumbers/form/field.rb', line 18

def self.label_id(input_id)
  [input_id, "label"].compact.join("_")
end

Instance Method Details

#label_hidden?Boolean

Returns:

  • (Boolean)


27
28
29
# File 'lib/stimulus_plumbers/form/field.rb', line 27

def label_hidden?
  @hide_label
end

#render(object, attribute, input_id:, &block) ⇒ Object



31
32
33
34
35
36
37
38
39
# File 'lib/stimulus_plumbers/form/field.rb', line 31

def render(object, attribute, input_id:, &block)
  @label ||= attribute.to_s.humanize
  case @floating
  when *FLOATING_TYPES
    render_floating_field(object, attribute, input_id, &block)
  else
    render_default_field(object, attribute, input_id, &block)
  end
end