Class: Admin::FieldsetComponent

Inherits:
ViewComponent::Base
  • Object
show all
Defined in:
lib/generators/infold/templates/install/app/components/admin/fieldset_component.rb

Instance Method Summary collapse

Constructor Details

#initialize(form, field = nil, kind = nil, required: false, label: nil, no_label: false, alignment: true, append: nil, prepend: nil, **options) ⇒ FieldsetComponent

Returns a new instance of FieldsetComponent.



5
6
7
8
9
10
11
12
13
14
15
16
# File 'lib/generators/infold/templates/install/app/components/admin/fieldset_component.rb', line 5

def initialize(form, field=nil, kind=nil, required: false, label: nil, no_label: false, alignment: true, append: nil, prepend: nil, **options)
  @form = form
  @field = field
  @kind = kind
  @required = required
  @label = label
  @no_label = no_label
  @alignment = alignment
  @append = append
  @prepend = prepend
  @options = options || {}
end

Instance Method Details

#alignment?Boolean

Returns:

  • (Boolean)


22
23
24
# File 'lib/generators/infold/templates/install/app/components/admin/fieldset_component.rb', line 22

def alignment?
  @alignment && label_rendering?
end

#form_fieldObject



26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
# File 'lib/generators/infold/templates/install/app/components/admin/fieldset_component.rb', line 26

def form_field
  case @kind
  when :checkbox
    Admin::CheckboxComponent.new(@form,
                                 @field,
                                 @options[:list],
                                 checked_values: @options[:checked_values])
  when :datetime
    Admin::DatetimeComponent.new(@form, @field)
  when :file
    Admin::FileUploadComponent.new(@form, @field)
  when :radio
    Admin::RadioComponent.new(@form,
                              @field,
                              @options[:list],
                              checked_value: @options[:checked_value])
  when :select
    Admin::SelectComponent.new(@form,
                               @field,
                               @options[:list],
                               selected_value: @options[:selected_value],
                               blank: @options[:blank] || true)
  when :switch
    Admin::SwitchComponent.new(@form,
                               @field,
                               include_hidden: @options[:include_hidden])
  when :association_search
    Admin::AssociationFieldComponent.new(@options[:association_name],
                                         @options[:search_path],
                                         @form,
                                         @field,
                                         @options[:name_field],
                                         nested_form: @options[:nested_form])
  else
    kind = @kind == :text_area ? :text_area : "#{@kind}_field"
    Admin::TextComponent.new(@form,
                             @field,
                             form_kind: kind,
                             placeholder: @options[:placeholder],
                             datepicker: @options[:datepicker])
  end
end

#input_group?Boolean

Returns:

  • (Boolean)


69
70
71
# File 'lib/generators/infold/templates/install/app/components/admin/fieldset_component.rb', line 69

def input_group?
  @append || @prepend
end

#label_rendering?Boolean

Returns:

  • (Boolean)


18
19
20
# File 'lib/generators/infold/templates/install/app/components/admin/fieldset_component.rb', line 18

def label_rendering?
  !@no_label
end