Class: Tailwinds::Form::Builder
- Inherits:
-
Tramway::Views::FormBuilder
- Object
- ActionView::Helpers::FormBuilder
- Tramway::Views::FormBuilder
- Tailwinds::Form::Builder
- Includes:
- Tramway::Utils::Field
- Defined in:
- app/components/tailwinds/form/builder.rb
Overview
Provides Tailwind-styled forms
Instance Attribute Summary
Attributes inherited from Tramway::Views::FormBuilder
Instance Method Summary collapse
- #common_field(component_name, input_method, attribute, **options) ⇒ Object
- #date_field(attribute) ⇒ Object
- #email_field(attribute) ⇒ Object
- #file_field(attribute, **options) ⇒ Object
-
#initialize(object_name, object, template, options) ⇒ Builder
constructor
A new instance of Builder.
- #multiselect(attribute, collection, **options) ⇒ Object
- #number_field(attribute) ⇒ Object
- #password_field(attribute, **options) ⇒ Object
- #select(attribute, collection, **options) ⇒ Object
- #submit(action, **options) ⇒ Object
- #text_area(attribute) ⇒ Object
- #text_field(attribute) ⇒ Object
Methods included from Tramway::Utils::Field
Constructor Details
#initialize(object_name, object, template, options) ⇒ Builder
Returns a new instance of Builder.
11 12 13 14 15 |
# File 'app/components/tailwinds/form/builder.rb', line 11 def initialize(object_name, object, template, ) super @form_size = [:size] || ['size'] || :middle end |
Instance Method Details
#common_field(component_name, input_method, attribute, **options) ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'app/components/tailwinds/form/builder.rb', line 17 def common_field(component_name, input_method, attribute, **, &) = () component_class = "Tailwinds::Form::#{component_name.to_s.camelize}Component".constantize render(component_class.new( input: input(input_method), value: get_value(attribute, ), **(attribute, ) ), &) end |
#date_field(attribute) ⇒ Object
55 56 57 |
# File 'app/components/tailwinds/form/builder.rb', line 55 def date_field(attribute, **, &) common_field(:date_field, :date_field, attribute, **, &) end |
#email_field(attribute) ⇒ Object
34 35 36 |
# File 'app/components/tailwinds/form/builder.rb', line 34 def email_field(attribute, **, &) common_field(:text_field, :email_field, attribute, **, &) end |
#file_field(attribute, **options) ⇒ Object
59 60 61 62 63 64 |
# File 'app/components/tailwinds/form/builder.rb', line 59 def file_field(attribute, **, &) = () input = super(attribute, **.merge(class: :hidden)) render(Tailwinds::Form::FileFieldComponent.new(input:, **(attribute, )), &) end |
#multiselect(attribute, collection, **options) ⇒ Object
77 78 79 80 81 82 83 84 85 86 |
# File 'app/components/tailwinds/form/builder.rb', line 77 def multiselect(attribute, collection, **, &) = () render(Tailwinds::Form::MultiselectComponent.new( input: input(:text_field), value: [:value] || [:selected] || object.public_send(attribute), collection:, **(attribute, ) ), &) end |
#number_field(attribute) ⇒ Object
38 39 40 |
# File 'app/components/tailwinds/form/builder.rb', line 38 def number_field(attribute, **, &) common_field(:number_field, :number_field, attribute, **, &) end |
#password_field(attribute, **options) ⇒ Object
46 47 48 49 50 51 52 53 |
# File 'app/components/tailwinds/form/builder.rb', line 46 def password_field(attribute, **, &) = () render(Tailwinds::Form::TextFieldComponent.new( input: input(:password_field), **(attribute, ) ), &) end |
#select(attribute, collection, **options) ⇒ Object
66 67 68 69 70 71 72 73 74 75 |
# File 'app/components/tailwinds/form/builder.rb', line 66 def select(attribute, collection, **, &) = () render(Tailwinds::Form::SelectComponent.new( input: input(:select), value: [:selected] || object.public_send(attribute), collection: explicitly_add_blank_option(collection, ), **(attribute, ) ), &) end |
#submit(action, **options) ⇒ Object
88 89 90 91 92 |
# File 'app/components/tailwinds/form/builder.rb', line 88 def submit(action, **, &) = () render(Tailwinds::Form::SubmitButtonComponent.new(action, size: form_size, **), &) end |
#text_area(attribute) ⇒ Object
42 43 44 |
# File 'app/components/tailwinds/form/builder.rb', line 42 def text_area(attribute, **, &) common_field(:text_area, :text_area, attribute, **, &) end |
#text_field(attribute) ⇒ Object
30 31 32 |
# File 'app/components/tailwinds/form/builder.rb', line 30 def text_field(attribute, **, &) common_field(:text_field, :text_field, attribute, **, &) end |