Module: ActiveForm::Mixins::ContainerMethods
Defined Under Namespace
Modules: ClassMethods, ElementMethods
Class Method Summary
collapse
Instance Method Summary
collapse
Instance Method Details
#bound_value?(name) ⇒ Boolean
27
28
29
|
# File 'lib/active_form/mixins/container_methods.rb', line 27
def bound_value?(name)
self.element_value.bound_value?(name)
end
|
#define_localizer(prc = nil, &block) ⇒ Object
Also known as:
localizer=
95
96
97
|
# File 'lib/active_form/mixins/container_methods.rb', line 95
def define_localizer(prc = nil, &block)
@localizer = (block_given? ? block : prc)
end
|
#description ⇒ Object
90
91
92
93
|
# File 'lib/active_form/mixins/container_methods.rb', line 90
def description
return (localize(nil, 'description') || @description) if localized?
@description
end
|
#export_value(values = ActiveForm::Values.new) ⇒ Object
Also known as:
export_values
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
|
# File 'lib/active_form/mixins/container_methods.rb', line 31
def export_value(values = ActiveForm::Values.new)
elements.inject(values) do |vals, elem|
if elem.group.blank?
vals[elem.name] = elem.export_value
else
if elem.element_type == :radio
vals[elem.group] ||= nil
vals[elem.group] = elem.export_value unless elem.blank?
else
vals[elem.group] ||= []
vals[elem.group] << elem.export_value unless elem.blank?
end
end
vals
end
end
|
#get_bound_value(name) ⇒ Object
19
20
21
|
# File 'lib/active_form/mixins/container_methods.rb', line 19
def get_bound_value(name)
self.element_value.bound_value(name) rescue nil
end
|
80
81
82
83
|
# File 'lib/active_form/mixins/container_methods.rb', line 80
def label
return (localize(nil, 'label') || @label) if localized?
@label
end
|
#localize(*args) ⇒ Object
100
101
102
|
# File 'lib/active_form/mixins/container_methods.rb', line 100
def localize(*args)
@localizer.call(identifier, *args) if localized?
end
|
#localized? ⇒ Boolean
104
105
106
|
# File 'lib/active_form/mixins/container_methods.rb', line 104
def localized?
(@localizer ||= nil).kind_of?(Proc)
end
|
#localizer ⇒ Object
108
109
110
|
# File 'lib/active_form/mixins/container_methods.rb', line 108
def localizer
localized? ? @localizer : nil
end
|
#set_bound_value(name, value) ⇒ Object
23
24
25
|
# File 'lib/active_form/mixins/container_methods.rb', line 23
def set_bound_value(name, value)
self.element_value.bound_value(name, value) rescue nil
end
|
#submitted? ⇒ Boolean
Also known as:
sent?
14
15
16
|
# File 'lib/active_form/mixins/container_methods.rb', line 14
def submitted?
not get_elements_of_type(:submit).all?(&:blank?)
end
|
85
86
87
88
|
# File 'lib/active_form/mixins/container_methods.rb', line 85
def title
return (localize(nil, 'title') || attributes[:title]) if localized?
attributes[:title]
end
|
#update_from_params(params, force = false) ⇒ Object
Also known as:
update_values_from_params, params=
65
66
67
68
69
70
71
72
73
74
75
76
|
# File 'lib/active_form/mixins/container_methods.rb', line 65
def update_from_params(params, force = false)
if params.respond_to?(:key?) && !params.empty?
value = ActiveForm::Values.new(params) rescue default_value
value = (value[self.name] || value[self.name.to_s] || default_value) unless self.contained?
elements.each do |e|
e.update_from_params(value[e.name] || e.default_value) if force || value.key?(e.name) || e.respond_to?(:checked?)
end
else
self.element_value = default_value
end
self.element_value
end
|
#update_value(value, force = false) ⇒ Object
Also known as:
update_values
49
50
51
52
53
54
55
56
57
58
59
60
61
62
|
# File 'lib/active_form/mixins/container_methods.rb', line 49
def update_value(value, force = false)
if self.contained?
self.element_value = value
else
if value.respond_to?(:key?) && !value.empty?
elements.each do |e|
e.update_value(value[e.name] || e.default_value) if force || value.key?(e.name) || e.respond_to?(:checked?)
end
else
self.element_value = default_value
end
self.element_value
end
end
|
#validated? ⇒ Boolean
10
11
12
|
# File 'lib/active_form/mixins/container_methods.rb', line 10
def validated?
submitted? && validate
end
|