Class: Formize::Definition::Group
- Inherits:
-
FormElement
- Object
- FormElement
- Formize::Definition::Group
- Defined in:
- lib/formize/definition/field_set.rb
Overview
Represents a group of fields which can depend on other fields
Direct Known Subclasses
Instance Attribute Summary collapse
-
#html_options ⇒ Object
readonly
Returns the value of attribute html_options.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#options ⇒ Object
readonly
Returns the value of attribute options.
Attributes inherited from FormElement
#children, #depend_on, #form, #html_id, #id, #parent, #unique_name
Instance Method Summary collapse
- #field(name, options = {}) ⇒ Object
- #field_set(name = nil, options = {}) {|field_set| ... } ⇒ Object
- #fields(*args) ⇒ Object
- #group(name = nil, options = {}) {|group| ... } ⇒ Object
-
#initialize(form, parent, name = nil, options = {}) ⇒ Group
constructor
A new instance of Group.
Methods inherited from FormElement
#all_elements, #all_fields, #arguments, #dependeds, #dependents, #dependents_on, #hidden_if, #mono_choices, #prototype, #shown_if
Constructor Details
#initialize(form, parent, name = nil, options = {}) ⇒ Group
Returns a new instance of Group.
9 10 11 12 13 14 15 16 17 18 19 20 |
# File 'lib/formize/definition/field_set.rb', line 9 def initialize(form, parent, name=nil, ={}) super(form, parent, ) @name = if name.blank? rand.to_s[2..-1].to_i.to_s(36) else raise ArgumentError.new("Name of group must be written only with a-z and 0-9 and _ (not #{name.inspect})") unless name.to_s == name.to_s.downcase.gsub(/[^a-z0-9\_]/, '') name.to_s end @depend_on = .delete(:depend_on) raise ArgumentError.new("A depended element must defined before its dependencies (#{@depended.inspect})") if !@depend_on.blank? and form.all_fields[@depend_on].nil? @html_options = @options.delete(:html_options)||{} end |
Instance Attribute Details
#html_options ⇒ Object (readonly)
Returns the value of attribute html_options.
7 8 9 |
# File 'lib/formize/definition/field_set.rb', line 7 def @html_options end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
7 8 9 |
# File 'lib/formize/definition/field_set.rb', line 7 def name @name end |
#options ⇒ Object (readonly)
Returns the value of attribute options.
7 8 9 |
# File 'lib/formize/definition/field_set.rb', line 7 def @options end |
Instance Method Details
#field(name, options = {}) ⇒ Object
36 37 38 |
# File 'lib/formize/definition/field_set.rb', line 36 def field(name, ={}) self.new_child(Field, name, ) end |
#field_set(name = nil, options = {}) {|field_set| ... } ⇒ Object
23 24 25 26 27 |
# File 'lib/formize/definition/field_set.rb', line 23 def field_set(name=nil, ={}, &block) raise ArgumentError.new("Missing block") unless block_given? field_set = self.new_child(FieldSet, name, ) yield field_set end |
#fields(*args) ⇒ Object
40 41 42 43 44 45 46 |
# File 'lib/formize/definition/field_set.rb', line 40 def fields(*args) = {} = args.delete_at(-1) if args[-1].is_a?(Hash) for name in args self.new_child(Field, name, ) end end |
#group(name = nil, options = {}) {|group| ... } ⇒ Object
29 30 31 32 33 34 |
# File 'lib/formize/definition/field_set.rb', line 29 def group(name=nil, ={}, &block) raise ArgumentError.new("Missing block") unless block_given? name, = nil, name if name.is_a? Hash group = self.new_child(Group, name, ) yield group end |