Class: PhlexKit::Form

Inherits:
BaseComponent show all
Defined in:
app/components/phlex_kit/form/form.rb

Overview

Form shell, ported from ruby_ui's RubyUI::Form. A plain

that stacks PhlexKit::FormFields with rhythm (.pk-form, form.css — plus .pk-form-actions for the submit/cancel row). Live validation lives on each FormField (see form_field.rb), so this stays markup-only:

render PhlexKit::Form.new(action: "/reviews", method: "post") do
render PhlexKit::FormField.new do
  render PhlexKit::FormFieldLabel.new(for: "email") { "Email" }
  render PhlexKit::Input.new(type: :email, id: "email", name: "email", required: true)
  render PhlexKit::FormFieldError.new
end
div(class: "pk-form-actions") { render PhlexKit::Button.new(type: :submit) { "Save" } }
end

With Rails form helpers, put the class on the builder instead: form_with(..., class: "pk-form").

Instance Method Summary collapse

Methods inherited from BaseComponent

#on

Constructor Details

#initialize(**attrs) ⇒ Form

Returns a new instance of Form.



19
20
21
# File 'app/components/phlex_kit/form/form.rb', line 19

def initialize(**attrs)
  @attrs = attrs
end

Instance Method Details

#view_templateObject



23
24
25
# File 'app/components/phlex_kit/form/form.rb', line 23

def view_template(&)
  form(**mix({ class: "pk-form" }, @attrs), &)
end