Class: Domino::Form::Field

Inherits:
Object
  • Object
show all
Defined in:
lib/domino/form/field.rb

Direct Known Subclasses

BooleanField, SelectField

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, locator, options = {}, &callback) ⇒ Field

Returns a new instance of Field.



4
5
6
7
8
9
10
# File 'lib/domino/form/field.rb', line 4

def initialize(name, locator, options = {}, &callback)
  @name = name
  @locator = locator
  @options = options
  @callback = callback
  extract_field_options
end

Instance Attribute Details

#callbackObject (readonly)

Returns the value of attribute callback.



2
3
4
# File 'lib/domino/form/field.rb', line 2

def callback
  @callback
end

#locatorObject (readonly)

Returns the value of attribute locator.



2
3
4
# File 'lib/domino/form/field.rb', line 2

def locator
  @locator
end

#nameObject (readonly)

Returns the value of attribute name.



2
3
4
# File 'lib/domino/form/field.rb', line 2

def name
  @name
end

#optionsObject (readonly)

Returns the value of attribute options.



2
3
4
# File 'lib/domino/form/field.rb', line 2

def options
  @options
end

Instance Method Details

#extract_field_optionsObject

Delete any options for your field type that shouldn’t be passed to the field locator. Default: noop



15
# File 'lib/domino/form/field.rb', line 15

def extract_field_options; end

#field(node) ⇒ Object

Locate the field using the locator and options



28
29
30
# File 'lib/domino/form/field.rb', line 28

def field(node)
  node.find_field(locator, options)
end

#read(node) ⇒ Object

Value that will be passed to the callback. Default: field_node.value



34
35
36
# File 'lib/domino/form/field.rb', line 34

def read(node)
  field(node).value
end

#value(node) ⇒ Object

Convert the value from ‘#read` via callback if provided.



18
19
20
21
22
23
24
25
# File 'lib/domino/form/field.rb', line 18

def value(node)
  val = read(node)
  if val && callback.is_a?(Proc)
    callback.call(val)
  else
    val
  end
end

#write(node, value) ⇒ Object

Sets the value on the field node. Default: node.fill_in for text fields.



40
41
42
# File 'lib/domino/form/field.rb', line 40

def write(node, value)
  node.fill_in(locator, with: value, **options)
end