Class: Formtastic::Inputs::ListInput

Inherits:
Object
  • Object
show all
Includes:
Base, Formtastic::InputHelpers
Defined in:
lib/formtastic/inputs/list_input.rb

Instance Method Summary collapse

Methods included from Formtastic::InputHelpers

#ci_hidden_field, #ci_text_field, #icon_tag, #input_classes

Instance Method Details

#has_quantity?Boolean

Returns:

  • (Boolean)


7
8
9
10
11
12
13
# File 'lib/formtastic/inputs/list_input.rb', line 7

def has_quantity?
  if @has_quantity.nil?
    @has_quantity = options[:has_quantity]
    @has_quantity = true if @has_quantity.nil?
  end
  @has_quantity
end

#to_htmlObject



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/formtastic/inputs/list_input.rb', line 15

def to_html
  fields = options[:fields] # [{'Header Text': :key}... ]
  values = @object ? @object.send(method) : nil

  input_wrapping do
    label_html <<
        template.(:div, class: 'item-quantity-group') do
          tags = select_html
          tags << quantity_html if has_quantity?
          tags << buttons(false)
        end <<
        template.(:div, nil, class: 'item-list-container') do
          # Table
          template.(:table, class: 'item-table') do
            # Headers
            template.(:tr) do
              headers = fields.map {|field|
                header = field.first[0]
                template.(:th, header.to_s)
              }.join.html_safe
              # Quantity header
              headers << template.(:th, 'Quantity') if has_quantity?
              # Button header
              headers << template.(:th)
            end <<
                table_row << #hidden template row for js use.
                if values
                  values.map {|value| table_row(false, value)}.join.html_safe
                end
          end
        end
  end
end