Class: Shadcn::FormBuilder

Inherits:
ActionView::Helpers::FormBuilder
  • Object
show all
Defined in:
app/components/shadcn/form_builder.rb

Instance Method Summary collapse

Instance Method Details

#email_field(method, options = {}) ⇒ Object



30
31
32
33
34
35
36
37
38
39
# File 'app/components/shadcn/form_builder.rb', line 30

def email_field(method, options = {})
  error_class = @object.errors[method].any? ? "error" : ""
  options[:class] = @template.tw("#{options[:class]} #{error_class}")
  @template.render_input(
    name: "#{object_name}[#{method}]",
    id: "#{object_name}_#{method}",
    value: @object.send(method),
    type: "email", **options
  )
end

#label(method, options = {}) ⇒ Object



2
3
4
5
6
# File 'app/components/shadcn/form_builder.rb', line 2

def label(method, options = {})
  error_class = @object.errors[method].any? ? "error" : ""
  options[:class] = @template.tw("#{options[:class]} #{error_class}")
  @template.render_label(name: "#{object_name}[#{method}]", label: label_for(@object, method), **options)
end

#password_field(method, options = {}) ⇒ Object



19
20
21
22
23
24
25
26
27
28
# File 'app/components/shadcn/form_builder.rb', line 19

def password_field(method, options = {})
  error_class = @object.errors[method].any? ? "error" : ""
  options[:class] = @template.tw("#{options[:class]} #{error_class}")
  @template.render_input(
    name: "#{object_name}[#{method}]",
    id: "#{object_name}_#{method}",
    value: @object.send(method),
    type: "password", **options
  )
end

#submit(value = nil, options = {}) ⇒ Object



52
53
54
# File 'app/components/shadcn/form_builder.rb', line 52

def submit(value = nil, options = {})
  @template.render_button(value, **options)
end

#text_area(method, options = {}) ⇒ Object



41
42
43
44
45
46
47
48
49
50
# File 'app/components/shadcn/form_builder.rb', line 41

def text_area(method, options = {})
  error_class = @object.errors[method].any? ? "error" : ""
  options[:class] = @template.tw("#{options[:class]} #{error_class}")
  @template.render_textarea(
    name: "#{object_name}[#{method}]",
    id: "#{object_name}_#{method}",
    value: @object.send(method),
    type: "text", **options
  )
end

#text_field(method, options = {}) ⇒ Object



8
9
10
11
12
13
14
15
16
17
# File 'app/components/shadcn/form_builder.rb', line 8

def text_field(method, options = {})
  error_class = @object.errors[method].any? ? "error" : ""
  options[:class] = @template.tw("#{options[:class]} #{error_class}")
  @template.render_input(
    name: "#{object_name}[#{method}]",
    id: "#{object_name}_#{method}",
    value: @object.send(method),
    type: "text", **options
  )
end