Module: Formular::Element::Modules::Checkable::InstanceMethods

Defined in:
lib/formular/element/modules/checkable.rb

Instance Method Summary collapse

Instance Method Details

#collectionObject



49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
# File 'lib/formular/element/modules/checkable.rb', line 49

def collection
  unless collection?
    options[:label_options] = options[:control_label_options]
    return [self]
  end

  base_options = collection_base_options

  @collection ||= options[:collection].map do |item|
    opts = base_options.dup
    opts[:value] = item.send(options[:value_method])
    opts[:label] = item.send(options[:label_method])

    opts[:id] = if options[:id]
                  "#{options[:id]}_#{opts[:value]}"
                else
                  "#{attribute_name || options[:name].gsub('[]', '')}_#{opts[:value]}"
                end

    self.class.(opts)
  end
end

#collection?Boolean

Returns:

  • (Boolean)


72
73
74
# File 'lib/formular/element/modules/checkable.rb', line 72

def collection?
  options[:collection]
end

#group_labelObject



38
39
40
41
42
43
# File 'lib/formular/element/modules/checkable.rb', line 38

def group_label
  return '' unless has_group_label?
  label_opts = label_options.dup
  label_opts[:content] = label_text
  builder.checkable_group_label(label_opts).to_s
end

#has_group_label?Boolean

Returns:

  • (Boolean)


45
46
47
# File 'lib/formular/element/modules/checkable.rb', line 45

def has_group_label?
  collection.size > 1 && has_label?
end