Class: Forms::Live::Field
- Inherits:
-
Field
- Object
- Field
- Forms::Live::Field
- Defined in:
- lib/forms/live/field.rb
Overview
A Forms::Field that merges the blur-time validate trigger into every input's data attributes (via apply_validations, the seam every builder already routes options through).
Instance Method Summary collapse
- #apply_validations(options) ⇒ Object
-
#initialize(live_trigger: nil) ⇒ Field
constructor
A new instance of Field.
-
#tag_field(*modifiers, suggestions: []) ⇒ Object
When THIS field is the form's declared
live_tagsfield, render the ROOTLESS variant: no nested reactive root, so the outer
Constructor Details
#initialize(live_trigger: nil) ⇒ Field
Returns a new instance of Field.
9 10 11 12 |
# File 'lib/forms/live/field.rb', line 9 def initialize(live_trigger: nil, **) super(**) @live_trigger = live_trigger end |
Instance Method Details
#apply_validations(options) ⇒ Object
14 15 16 17 18 19 |
# File 'lib/forms/live/field.rb', line 14 def apply_validations() merged = super return merged unless @live_trigger merged.merge(data: merge_data(merged[:data], @live_trigger[:data])) end |
#tag_field(*modifiers, suggestions: []) ⇒ Object
When THIS field is the form's declared live_tags field, render the
ROOTLESS variant: no nested reactive root, so the outer
26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/forms/live/field.rb', line 26 def tag_field(*modifiers, suggestions: [], **) declaration = @form.class.respond_to?(:live_tags_declaration) && @form.class. return super unless declaration && declaration[:name] == @name # Call-site suggestions win; otherwise fall back to the declaration's. suggestions = declaration[:suggestions] if blank_suggestions?(suggestions) theme[:rootless_tag_field].new( *modifiers, name: field_name, id: field_id, value: field_value, suggestions:, error: invalid?, ** ) end |