Class: Tailwinds::Form::Builder

Inherits:
Tramway::Views::FormBuilder show all
Defined in:
app/components/tailwinds/form/builder.rb

Overview

Provides Tailwind-styled forms :reek:InstanceVariableAssumption

Instance Attribute Summary

Attributes inherited from Tramway::Views::FormBuilder

#template

Instance Method Summary collapse

Instance Method Details

#file_field(attribute, **options) ⇒ Object



23
24
25
26
27
# File 'app/components/tailwinds/form/builder.rb', line 23

def file_field(attribute, **options, &)
  input = super(attribute, **options.merge(class: :hidden))

  render(Tailwinds::Form::FileFieldComponent.new(input:, **default_options(attribute, options)), &)
end

#multiselect(attribute, collection, **options) ⇒ Object



38
39
40
41
42
43
44
45
# File 'app/components/tailwinds/form/builder.rb', line 38

def multiselect(attribute, collection, **options, &)
  render(Tailwinds::Form::MultiselectComponent.new(
           input: input(:text_field),
           value: options[:value] || options[:selected] || object.public_send(attribute)&.first,
           collection:,
           **default_options(attribute, options)
         ), &)
end

#password_field(attribute, **options) ⇒ Object



16
17
18
19
20
21
# File 'app/components/tailwinds/form/builder.rb', line 16

def password_field(attribute, **options, &)
  render(Tailwinds::Form::TextFieldComponent.new(
           input: input(:password_field),
           **default_options(attribute, options)
         ), &)
end

#select(attribute, collection, **options) ⇒ Object



29
30
31
32
33
34
35
36
# File 'app/components/tailwinds/form/builder.rb', line 29

def select(attribute, collection, **options, &)
  render(Tailwinds::Form::SelectComponent.new(
           input: input(:select),
           value: options[:selected] || object.public_send(attribute),
           collection: explicitly_add_blank_option(collection, options),
           **default_options(attribute, options)
         ), &)
end

#submit(action) ⇒ Object



47
48
49
# File 'app/components/tailwinds/form/builder.rb', line 47

def submit(action, **, &)
  render(Tailwinds::Form::SubmitButtonComponent.new(action, **), &)
end

#text_field(attribute, **options) ⇒ Object



8
9
10
11
12
13
14
# File 'app/components/tailwinds/form/builder.rb', line 8

def text_field(attribute, **options, &)
  render(Tailwinds::Form::TextFieldComponent.new(
           input: input(:text_field),
           value: get_value(attribute, options),
           **default_options(attribute, options)
         ), &)
end