Module: OpenRosa::FormDSL
- Included in:
- Form
- Defined in:
- lib/open_rosa/form_dsl.rb
Overview
DSL methods for defining form fields
Instance Method Summary collapse
-
#boolean(name, options = {}) ⇒ Object
DSL method to add a boolean field.
-
#fields ⇒ Object
Returns array of all fields defined in this form.
-
#group(name, options = {}) ⇒ Object
DSL method to add a group field with nested fields.
-
#input(name, options = {}) ⇒ Object
DSL method to add an input field.
-
#range(name, options = {}) ⇒ Object
DSL method to add a range field.
-
#repeat(name, options = {}) ⇒ Object
DSL method to add a repeat field with nested fields.
-
#select(name, options = {}) ⇒ Object
DSL method to add a select field (multiple select).
-
#select1(name, options = {}) ⇒ Object
DSL method to add a select1 field (single select).
-
#trigger(name, options = {}) ⇒ Object
DSL method to add a trigger field.
-
#upload(name, options = {}) ⇒ Object
DSL method to add an upload field.
Instance Method Details
#boolean(name, options = {}) ⇒ Object
DSL method to add a boolean field
27 28 29 |
# File 'lib/open_rosa/form_dsl.rb', line 27 def boolean(name, = {}) fields << Fields::Boolean.new(name, ) end |
#fields ⇒ Object
Returns array of all fields defined in this form
7 8 9 |
# File 'lib/open_rosa/form_dsl.rb', line 7 def fields @fields ||= [] end |
#group(name, options = {}) ⇒ Object
DSL method to add a group field with nested fields
47 48 49 50 51 52 53 54 55 56 |
# File 'lib/open_rosa/form_dsl.rb', line 47 def group(name, = {}, &) # Create a temporary context to collect nested fields nested_fields = [] if block_given? context = FieldContext.new(nested_fields) context.instance_eval(&) end fields << Fields::Group.new(name, .merge(fields: nested_fields)) end |
#input(name, options = {}) ⇒ Object
DSL method to add an input field
12 13 14 |
# File 'lib/open_rosa/form_dsl.rb', line 12 def input(name, = {}) fields << Fields::Input.new(name, ) end |
#range(name, options = {}) ⇒ Object
DSL method to add a range field
37 38 39 |
# File 'lib/open_rosa/form_dsl.rb', line 37 def range(name, = {}) fields << Fields::Range.new(name, ) end |
#repeat(name, options = {}) ⇒ Object
DSL method to add a repeat field with nested fields
59 60 61 62 63 64 65 66 67 68 |
# File 'lib/open_rosa/form_dsl.rb', line 59 def repeat(name, = {}, &) # Create a temporary context to collect nested fields nested_fields = [] if block_given? context = FieldContext.new(nested_fields) context.instance_eval(&) end fields << Fields::Repeat.new(name, .merge(fields: nested_fields)) end |
#select(name, options = {}) ⇒ Object
DSL method to add a select field (multiple select)
22 23 24 |
# File 'lib/open_rosa/form_dsl.rb', line 22 def select(name, = {}) fields << Fields::Select.new(name, ) end |
#select1(name, options = {}) ⇒ Object
DSL method to add a select1 field (single select)
17 18 19 |
# File 'lib/open_rosa/form_dsl.rb', line 17 def select1(name, = {}) fields << Fields::Select1.new(name, ) end |
#trigger(name, options = {}) ⇒ Object
DSL method to add a trigger field
42 43 44 |
# File 'lib/open_rosa/form_dsl.rb', line 42 def trigger(name, = {}) fields << Fields::Trigger.new(name, ) end |
#upload(name, options = {}) ⇒ Object
DSL method to add an upload field
32 33 34 |
# File 'lib/open_rosa/form_dsl.rb', line 32 def upload(name, = {}) fields << Fields::Upload.new(name, ) end |