Class: Shoelace::SlFormBuilder

Inherits:
ActionView::Helpers::FormBuilder
  • Object
show all
Defined in:
app/helpers/shoelace/sl_form_builder.rb

Overview

:nodoc:

Instance Method Summary collapse

Instance Method Details

#check_box(method, options = {}, checked_value = "1", unchecked_value = "0", &block) ⇒ Object



68
69
70
# File 'app/helpers/shoelace/sl_form_builder.rb', line 68

def check_box(method, options = {}, checked_value = "1", unchecked_value = "0", &block)
  Components::SlCheckbox.new(object_name, method, @template, checked_value, unchecked_value, options.with_defaults(label: label_text(method)).merge(object: @object)).render(&block)
end

#collection_radio_buttons(method, collection, value_method, text_method, options = {}, html_options = {}, &block) ⇒ Object



87
88
89
# File 'app/helpers/shoelace/sl_form_builder.rb', line 87

def collection_radio_buttons(method, collection, value_method, text_method, options = {}, html_options = {}, &block)
  Components::SlCollectionRadioButtons.new(object_name, method, @template, collection, value_method, text_method, options.with_defaults(object: @object, label: label_text(method)), html_options).render(&block)
end

#collection_select(method, collection, value_method, text_method, options = {}, html_options = {}, &block) ⇒ Object



77
78
79
80
# File 'app/helpers/shoelace/sl_form_builder.rb', line 77

def collection_select(method, collection, value_method, text_method, options = {}, html_options = {}, &block)
  slot = wrap_with_default_slot(method, &block)
  Components::SlCollectionSelect.new(object_name, method, @template, collection, value_method, text_method, options.with_defaults(object: @object), html_options.with_defaults(label: label_text(method)), slot).render
end

#color_field(method, **options) ⇒ Object Also known as: color_picker



45
46
47
# File 'app/helpers/shoelace/sl_form_builder.rb', line 45

def color_field(method, **options)
  Components::SlColorPicker.new(object_name, method, @template, options.with_defaults(object: @object, label: label_text(method))).render
end

#grouped_collection_select(method, collection, group_method, group_label_method, option_key_method, option_value_method, options = {}, html_options = {}, &block) ⇒ Object



82
83
84
85
# File 'app/helpers/shoelace/sl_form_builder.rb', line 82

def grouped_collection_select(method, collection, group_method, group_label_method, option_key_method, option_value_method, options = {}, html_options = {}, &block)
  slot = wrap_with_default_slot(method, &block)
  Components::SlGroupedCollectionSelect.new(object_name, method, @template, collection, group_method, group_label_method, option_key_method, option_value_method, options.with_defaults(object: @object), html_options.with_defaults(label: label_text(method)), slot).render
end

#range_field(method, **options) ⇒ Object Also known as: range



50
51
52
# File 'app/helpers/shoelace/sl_form_builder.rb', line 50

def range_field(method, **options)
  Components::SlRange.new(object_name, method, @template, options.with_defaults(object: @object, label: label_text(method))).render
end

#select(method, choices = nil, options = {}, html_options = {}, &block) ⇒ Object



72
73
74
75
# File 'app/helpers/shoelace/sl_form_builder.rb', line 72

def select(method, choices = nil, options = {}, html_options = {}, &block)
  slot = wrap_with_default_slot(method, &block)
  Components::SlSelect.new(object_name, method, @template, choices, options.with_defaults(object: @object), html_options.with_defaults(label: label_text(method)), slot).render
end

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



91
92
93
94
95
# File 'app/helpers/shoelace/sl_form_builder.rb', line 91

def submit(value = nil, options = {})
  value, options = nil, value if value.is_a?(Hash)

  @template.sl_submit_tag(value || submit_default_value, **options)
end

#switch_field(method, **options, &block) ⇒ Object Also known as: switch



55
56
57
58
59
60
61
# File 'app/helpers/shoelace/sl_form_builder.rb', line 55

def switch_field(method, **options, &block)
  if block_given?
    Components::SlSwitch.new(object_name, method, @template, options.with_defaults(object: @object)).render(&block)
  else
    Components::SlSwitch.new(object_name, method, @template, options.with_defaults(object: @object, label: label_text(method))).render(&block)
  end
end

#text_area(method, **options, &block) ⇒ Object



64
65
66
# File 'app/helpers/shoelace/sl_form_builder.rb', line 64

def text_area(method, **options, &block)
  Components::SlTextarea.new(object_name, method, @template, options.with_defaults(object: @object, label: label_text(method), resize: 'auto')).render(&block)
end