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

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, options = {})
  fields << Fields::Boolean.new(name, options)
end

#fieldsObject

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, options = {}, &)
  # 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, options.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, options = {})
  fields << Fields::Input.new(name, options)
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, options = {})
  fields << Fields::Range.new(name, options)
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, options = {}, &)
  # 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, options.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, options = {})
  fields << Fields::Select.new(name, options)
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, options = {})
  fields << Fields::Select1.new(name, options)
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, options = {})
  fields << Fields::Trigger.new(name, options)
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, options = {})
  fields << Fields::Upload.new(name, options)
end