Class: PushType::RepeaterField
Instance Attribute Summary
Attributes inherited from FieldType
#model, #name
Instance Method Summary
collapse
Methods inherited from FieldType
#css_class, #field_options, #form_helper, #html_options, #json_primitive, #json_value, #kind, #label, #multiple?, on_class, on_instance, options, #primitive
Constructor Details
Returns a new instance of RepeaterField.
7
8
9
10
11
12
13
14
15
|
# File 'app/fields/push_type/repeater_field.rb', line 7
def initialize(*args)
super
raise ArgumentError, "Invalid field type. `#{ @opts[:repeats] }` cannot be used in #{ self.class.name }." if [:tag_list].include?(@opts[:repeats])
_key, _opts = structure_json_key, @opts
structure_class.class_eval do
field _key, _opts[:repeats], _opts.except(:css_class, :repeats).merge(multiple: false)
define_method(:f) { fields[_key] }
end
end
|
Instance Method Details
26
27
28
29
30
|
# File 'app/fields/push_type/repeater_field.rb', line 26
def rows
Array(json_value).map do |j|
structure_class.new(field_store: { structure_json_key => j }.as_json)
end
end
|
#structure ⇒ Object
32
33
34
|
# File 'app/fields/push_type/repeater_field.rb', line 32
def structure
@structure ||= structure_class.new
end
|
22
23
24
|
# File 'app/fields/push_type/repeater_field.rb', line 22
def template
'repeater'
end
|
17
18
19
20
|
# File 'app/fields/push_type/repeater_field.rb', line 17
def value
return if json_value.blank?
rows.reject(&:blank?).map(&:_f)
end
|