Module: CoreFormInputHelper

Defined in:
app/helpers/core_form_input_helper.rb

Instance Method Summary collapse

Instance Method Details

#form_email_field(model, field, options = {}) ⇒ Object

This method is abstract.

Render a email text field

Parameters:

  • model (Mongoid::Document)
    • The model to render the field for

  • field (Symbol)
    • The field to render

  • options (Hash) (defaults to: {})
    • Options to pass to the field



18
19
20
21
# File 'app/helpers/core_form_input_helper.rb', line 18

def form_email_field(model, field, options = {})
  options[:type] ||= :email
  form_text_field(model, field, options)
end

#form_number_field(model, field, options = {}) ⇒ Object

This method is abstract.

Render a email text field

Parameters:

  • model (Mongoid::Document)
    • The model to render the field for

  • field (Symbol)
    • The field to render

  • options (Hash) (defaults to: {})
    • Options to pass to the field



7
8
9
10
11
12
# File 'app/helpers/core_form_input_helper.rb', line 7

def form_number_field(model, field, options = {})
  options[:type] ||= :number
  options[:step] ||= 1
  options[:min] ||= 0
  form_text_field(model, field, options)
end

#form_password(model, field, options = {}) ⇒ Object

This method is abstract.

Render a text field

Parameters:

  • model (Mongoid::Document)
    • The model to render the field for

  • field (Symbol)
    • The field to render

  • options (Hash) (defaults to: {})
    • Options to pass to the field



36
37
38
39
# File 'app/helpers/core_form_input_helper.rb', line 36

def form_password(model, field, options = {})
  options[:type] = :password
  form_text_field(model, field, options)
end

#form_text_field(model, field, options = {}) ⇒ Object

This method is abstract.

Render a text field

Parameters:

  • model (Mongoid::Document)
    • The model to render the field for

  • field (Symbol)
    • The field to render

  • options (Hash) (defaults to: {})
    • Options to pass to the field



45
46
47
48
49
50
51
52
53
54
55
56
57
58
# File 'app/helpers/core_form_input_helper.rb', line 45

def form_text_field(model, field, options = {})
  label_options = options.clone
  classes = options[:classes] || []
  classes << 'mb-3'
  value = model.send(field)
  options[:type] ||= :text
  options[:value] = value
  options[:disabled] ||= false
  tag_options = text_field_options(model, field, options)
  (:div, class: classes.join(' ')) do
    concat(form_label_tag(model, field, value, label_options))
    concat(tag(:input, tag_options))
  end
end

#form_url_field(model, field, options = {}) ⇒ Object

This method is abstract.

Render a text field

Parameters:

  • model (Mongoid::Document)
    • The model to render the field for

  • field (Symbol)
    • The field to render

  • options (Hash) (defaults to: {})
    • Options to pass to the field



27
28
29
30
# File 'app/helpers/core_form_input_helper.rb', line 27

def form_url_field(model, field, options = {})
  options[:type] ||= :url
  form_text_field(model, field, options)
end

#text_field_options(model, field, options = {}) ⇒ Object

This method is abstract.

Build the options for a text field, place holder, hint, etc.

Parameters:

  • model (Mongoid::Document)
    • The model to render the field for

  • field (Symbol)
    • The field to render

  • options (Hash) (defaults to: {})
    • Options to pass to the field



64
65
66
67
68
69
70
71
72
73
# File 'app/helpers/core_form_input_helper.rb', line 64

def text_field_options(model, field, options = {})
  classes = %w[form-control]
  classes += options[:input_classes] if options[:input_classes].present?
  options[:name] = form_field_name(model, field, options)
  options[:id] = form_field_id(model, field, options)
  place_holder = options[:place_holder] || form_place_holder_text(model, field)
  options[:placeholder] = place_holder if place_holder.present?
  options[:class] = classes.uniq
  options
end