class Basepack::Forms::Groups::Base
Attributes
delegate[R]
field_names[RW]
form[R]
Public Class Methods
new(form, delegate_or_attributes = nil)
click to toggle source
# File lib/basepack/forms/groups/base.rb, line 12 def initialize(form, delegate_or_attributes = nil) @form = form @field_names = [] update_attributes(delegate_or_attributes) end
Public Instance Methods
content_for_field(field_name, &block)
click to toggle source
# File lib/basepack/forms/groups/base.rb, line 34 def content_for_field(field_name, &block) field(field_name) do |f| f.content(&block) end end
field(name, delegate_or_attributes = nil, &block)
click to toggle source
# File lib/basepack/forms/groups/base.rb, line 28 def field(name, delegate_or_attributes = nil, &block) field = @form.field(name, delegate_or_attributes, &block) @field_names << name if field and !@field_names.include?(name) field end
fields()
click to toggle source
# File lib/basepack/forms/groups/base.rb, line 40 def fields @field_names.map {|f| @form.field(f)}.compact end
remove()
click to toggle source
# File lib/basepack/forms/groups/base.rb, line 48 def remove @form.groups.delete self end
update_attributes(delegate_or_attributes)
click to toggle source
# File lib/basepack/forms/groups/base.rb, line 18 def update_attributes(delegate_or_attributes) if delegate_or_attributes.is_a? Hash delegate_or_attributes.each do |a, v| send("#{a}=", v) end else @delegate = delegate_or_attributes end end
values()
click to toggle source
# File lib/basepack/forms/groups/base.rb, line 52 def values result = {} visible_fields.each {|f| result[f.name] = f.value} result end
values_without_blank()
click to toggle source
# File lib/basepack/forms/groups/base.rb, line 58 def values_without_blank result = {} visible_fields.each do |f| val = f.value.presence result[f.name] = val unless val.nil? end result end
visible_fields()
click to toggle source
# File lib/basepack/forms/groups/base.rb, line 44 def visible_fields @field_names.map {|f| @form.visible_field(f)}.compact end