Class: Forms::FormControl
- Inherits:
-
Phlex::HTML
- Object
- Phlex::HTML
- Forms::FormControl
- Defined in:
- lib/forms/form_control.rb
Overview
Wraps a field in the daisyui form-control layout: optional label on top, the
field (yielded block), then an error (if present) or a hint. This is the
workhorse behind the Control-first f.field API and the explicit f.Control
escape hatch.
Instance Method Summary collapse
-
#initialize(*modifiers, label: nil, hint: nil, error: nil, for: nil, required: false, **options) ⇒ FormControl
constructor
A new instance of FormControl.
- #view_template ⇒ Object
Constructor Details
#initialize(*modifiers, label: nil, hint: nil, error: nil, for: nil, required: false, **options) ⇒ FormControl
Returns a new instance of FormControl.
9 10 11 12 13 14 15 16 17 18 |
# File 'lib/forms/form_control.rb', line 9 def initialize(*modifiers, label: nil, hint: nil, error: nil, for: nil, required: false, **) @modifiers = modifiers @label = label @hint = hint @error = error @field_id = grab(for:) @required = required @options = super() end |
Instance Method Details
#view_template ⇒ Object
20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/forms/form_control.rb', line 20 def view_template(&) div(class: control_classes, **@options.except(:class)) do render Forms::Label.new(text: @label, for: @field_id, required: @required) if @label yield if block_given? if @error render Forms::FieldError.new(message: @error) elsif @hint render Forms::FieldHint.new(text: @hint) end end end |