Class: NitroKit::FormBuilder

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

Instance Method Summary collapse

Instance Method Details

#button(value = "Save changes", **options) ⇒ Object



38
39
40
41
# File 'app/components/nitro_kit/form_builder.rb', line 38

def button(value = "Save changes", **options)
  content = value || @template.capture(&block)
  @template.render(NitroKit::Button.new(**options)) { content }
end

#checkbox(method, options = {}) ⇒ Object Also known as: check_box



27
28
29
# File 'app/components/nitro_kit/form_builder.rb', line 27

def checkbox(method, options = {})
  @template.checkbox(@object_name, method, objectify_options(options), label: options[:label])
end

#field(object_name, **options) ⇒ Object



15
16
17
18
19
20
# File 'app/components/nitro_kit/form_builder.rb', line 15

def field(object_name, **options)
  label = options.fetch(:label, object_name.to_s.humanize)
  errors = object.errors.include?(object_name) ? object.errors.full_messages_for(object_name) : nil

  @template.render(NitroKit::Field.new(object_name, label:, errors:, **options))
end

#field_group(options = {}, &block) ⇒ Object



10
11
12
13
# File 'app/components/nitro_kit/form_builder.rb', line 10

def field_group(options = {}, &block)
  content = @template.capture(&block)
  @template.render(NitroKit::FieldGroup.new(**options)) { content }
end

#fieldset(options = {}, &block) ⇒ Object

Fields



5
6
7
8
# File 'app/components/nitro_kit/form_builder.rb', line 5

def fieldset(options = {}, &block)
  content = @template.capture(&block)
  @template.render(NitroKit::Fieldset.new(options)) { content }
end

#label(object_name, method, content_or_options = nil, options = nil, &block) ⇒ Object

Inputs



24
25
# File 'app/components/nitro_kit/form_builder.rb', line 24

def label(object_name, method, content_or_options = nil, options = nil, &block)
end

#submit(value = "Save changes", **options) ⇒ Object



33
34
35
36
# File 'app/components/nitro_kit/form_builder.rb', line 33

def submit(value = "Save changes", **options)
  content = value || @template.capture(&block)
  @template.render(NitroKit::Button.new(variant: :primary, type: :submit, **options)) { content }
end