Class: Admin::TextComponent

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

Instance Method Summary collapse

Constructor Details

#initialize(form, field, form_kind: nil, datepicker: false, timepicker: false, html_class: nil, placeholder: nil, rows: nil, data: nil) ⇒ TextComponent

Returns a new instance of TextComponent.



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

def initialize(form, field, form_kind: nil, datepicker: false, timepicker: false, html_class: nil, placeholder: nil, rows: nil, data: nil)
  @form = form
  @field = field
  @form_kind = form_kind || 'text_field'
  @datepicker = datepicker
  @timepicker = timepicker
  @class = html_class
  @data = data || {}
  @placeholder = placeholder
  @rows = rows
end

Instance Method Details

#callObject



36
37
38
# File 'lib/generators/infold/templates/install/app/components/admin/text_component.rb', line 36

def call
  text_field
end

#text_fieldObject



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/generators/infold/templates/install/app/components/admin/text_component.rb', line 17

def text_field
  if @datepicker
    @data[:controller] = 'datepicker'
  elsif @timepicker
    @data[:controller] = 'timepicker'
  end
  classes = %W(form-control #{@class})
  classes << 'datepicker' if @datepicker
  classes << 'timepicker' if @timepicker
  classes << 'is-invalid' if helpers.admin_field_invalid?(@form, @field)
  @form.send(@form_kind, @field,
             class: classes.join(' '),
             placeholder: @placeholder,
             data: @data,
             rows: @rows,
             autocomplete: 'off',
             step: @form_kind == 'number_field' ? :any : nil)
end