Class: Forms::Input

Inherits:
Phlex::HTML
  • Object
show all
Includes:
PhlexForms::DelegatedField
Defined in:
lib/forms/input.rb

Overview

A model-bound text-like input. Thin form-binding layer over DaisyUI::Input: it wires name/id/value/error/required onto the field, then delegates all markup and variant handling to the daisyui gem's component (which stacks positional color/size/style modifiers and passes a block straight through).

Forms::Input.new(:primary, :lg, type: "email", name: "user[email]")

w-full is added by default. For the daisyui v5 "icon/text inside the field" pattern (a

Direct Known Subclasses

EmailField, PasswordField

Constant Summary

Constants included from PhlexForms::DelegatedField

PhlexForms::DelegatedField::IGNORED_MODIFIERS

Instance Method Summary collapse

Constructor Details

#initialize(*modifiers, type: "text", name: nil, id: nil, value: nil, error: false, disabled: false, required: false, full_width: true, **attributes) ⇒ Input

Returns a new instance of Input.



16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/forms/input.rb', line 16

def initialize(*modifiers, type: "text", name: nil, id: nil, value: nil,
               error: false, disabled: false, required: false, full_width: true, **attributes)
  @modifiers = normalize_modifiers(modifiers)
  @type = type
  @name = name
  @id = id
  @value = value
  @error = error
  @disabled = disabled
  @required = required
  @full_width = full_width
  @attributes = attributes
  super()
end

Instance Method Details

#view_templateObject



31
32
33
# File 'lib/forms/input.rb', line 31

def view_template(&)
  render DaisyUI::Input.new(*daisy_modifiers, type: @type, value: @value.to_s, **binding_attributes, &)
end