Class: Domino::Form::Field
- Inherits:
-
Object
- Object
- Domino::Form::Field
- Defined in:
- lib/domino/form/field.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#callback ⇒ Object
readonly
Returns the value of attribute callback.
-
#locator ⇒ Object
readonly
Returns the value of attribute locator.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#options ⇒ Object
readonly
Returns the value of attribute options.
Instance Method Summary collapse
-
#extract_field_options ⇒ Object
Delete any options for your field type that shouldn’t be passed to the field locator.
-
#field(node) ⇒ Object
Locate the field using the locator and options.
-
#initialize(name, locator, options = {}, &callback) ⇒ Field
constructor
A new instance of Field.
-
#read(node) ⇒ Object
Value that will be passed to the callback.
-
#value(node) ⇒ Object
Convert the value from ‘#read` via callback if provided.
-
#write(node, value) ⇒ Object
Sets the value on the field node.
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, = {}, &callback) @name = name @locator = locator @options = @callback = callback end |
Instance Attribute Details
#callback ⇒ Object (readonly)
Returns the value of attribute callback.
2 3 4 |
# File 'lib/domino/form/field.rb', line 2 def callback @callback end |
#locator ⇒ Object (readonly)
Returns the value of attribute locator.
2 3 4 |
# File 'lib/domino/form/field.rb', line 2 def locator @locator end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
2 3 4 |
# File 'lib/domino/form/field.rb', line 2 def name @name end |
#options ⇒ Object (readonly)
Returns the value of attribute options.
2 3 4 |
# File 'lib/domino/form/field.rb', line 2 def @options end |
Instance Method Details
#extract_field_options ⇒ Object
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 ; 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, ) 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, **) end |