Class: Super::FormBuilder::Wrappers
- Inherits:
-
Object
- Object
- Super::FormBuilder::Wrappers
- Defined in:
- lib/super/form_builder.rb,
lib/super/form_builder/base_methods.rb,
lib/super/form_builder/option_methods.rb,
lib/super/form_builder/flatpickr_methods.rb,
lib/super/form_builder/action_text_methods.rb
Instance Method Summary collapse
- #check_box(attribute, options = {}, checked_value = "1", unchecked_value = "0") ⇒ Object
- #check_box!(attribute, checked_value: "1", unchecked_value: "0", label_text: nil, label: {}, field: {}, show_errors: true) ⇒ Object
- #collection_check_boxes(attribute, collection, value_method, text_method, options = {}, html_options = {}, &block) ⇒ Object
- #collection_radio_buttons(attribute, collection, value_method, text_method, options = {}, html_options = {}, &block) ⇒ Object
- #collection_select(attribute, collection, value_method, text_method, options = {}, html_options = {}) ⇒ Object
- #container(&block) ⇒ Object
- #date_flatpickr(attribute, options = {}) ⇒ Object
- #datetime_flatpickr(attribute, options = {}) ⇒ Object
- #grouped_collection_select(attribute, collection, group_method, group_label_method, option_key_method, option_value_method, options = {}, html_options = {}) ⇒ Object
- #hidden_field(attribute, options = {}) ⇒ Object
-
#initialize(builder, template) ⇒ Wrappers
constructor
A new instance of Wrappers.
- #inline_errors(attribute) ⇒ Object
- #label(attribute, text = nil, options = {}, &block) ⇒ Object
- #rich_text_area(attribute, options = {}) ⇒ Object
- #select(attribute, choices, options = {}, html_options = {}, &block) ⇒ Object
-
#submit(value = nil, options = {}) ⇒ Object
def radio_button(attribute, tag_value, label_text: nil, label: {}, field: {}, show_errors: true) end.
- #time_flatpickr(attribute, options = {}) ⇒ Object
- #time_zone_select(attribute, priority_zones = nil, options = {}, html_options = {}) ⇒ Object
Constructor Details
#initialize(builder, template) ⇒ Wrappers
Returns a new instance of Wrappers.
29 30 31 32 |
# File 'lib/super/form_builder.rb', line 29 def initialize(builder, template) @builder = builder @template = template end |
Instance Method Details
#check_box(attribute, options = {}, checked_value = "1", unchecked_value = "0") ⇒ Object
27 28 29 |
# File 'lib/super/form_builder/base_methods.rb', line 27 def check_box(attribute, = {}, checked_value = "1", unchecked_value = "0") @builder.check_box(attribute, , checked_value, unchecked_value) end |
#check_box!(attribute, checked_value: "1", unchecked_value: "0", label_text: nil, label: {}, field: {}, show_errors: true) ⇒ Object
31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/super/form_builder/base_methods.rb', line 31 def check_box!(attribute, checked_value: "1", unchecked_value: "0", label_text: nil, label: {}, field: {}, show_errors: true) label[:super] ||= {} label[:super] = {class: "select-none ml-1"}.merge(label[:super]) container do compact_join([ "<div>".html_safe, public_send(:check_box, attribute, field, checked_value, unchecked_value), public_send(:label, attribute, label_text, label), "</div>".html_safe, show_errors && inline_errors(attribute) ]) end end |
#collection_check_boxes(attribute, collection, value_method, text_method, options = {}, html_options = {}, &block) ⇒ Object
50 51 52 53 54 55 56 57 |
# File 'lib/super/form_builder/option_methods.rb', line 50 def collection_check_boxes(attribute, collection, value_method, text_method, = {}, = {}, &block) , defaults = split_defaults(, include_blank: true) = defaults.merge() , html_defaults = split_defaults(, class: "super-input super-input-select") [:class] = join_classes(html_defaults[:class], [:class]) @builder.collection_check_boxes(attribute, collection, value_method, text_method, , , &block) end |
#collection_radio_buttons(attribute, collection, value_method, text_method, options = {}, html_options = {}, &block) ⇒ Object
61 62 63 64 65 66 67 68 |
# File 'lib/super/form_builder/option_methods.rb', line 61 def (attribute, collection, value_method, text_method, = {}, = {}, &block) , defaults = split_defaults(, include_blank: true) = defaults.merge() , html_defaults = split_defaults(, class: "super-input super-input-select") [:class] = join_classes(html_defaults[:class], [:class]) @builder.(attribute, collection, value_method, text_method, , , &block) end |
#collection_select(attribute, collection, value_method, text_method, options = {}, html_options = {}) ⇒ Object
17 18 19 20 21 22 23 24 |
# File 'lib/super/form_builder/option_methods.rb', line 17 def collection_select(attribute, collection, value_method, text_method, = {}, = {}) , defaults = split_defaults(, include_blank: true) = defaults.merge() , html_defaults = split_defaults(, class: "super-input super-input-select") [:class] = join_classes(html_defaults[:class], [:class]) @builder.collection_select(attribute, collection, value_method, text_method, , ) end |
#container(&block) ⇒ Object
49 50 51 |
# File 'lib/super/form_builder.rb', line 49 def container(&block) @template.content_tag(:div, class: "super-field-group", &block) end |
#date_flatpickr(attribute, options = {}) ⇒ Object
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/super/form_builder/flatpickr_methods.rb', line 6 def date_flatpickr(attribute, = {}) , defaults = split_defaults( , class: "super-input w-full", data: { controller: "flatpickr", flatpickr_options_value: { dateFormat: "Y-m-d" } } ) [:class] = join_classes(defaults[:class], [:class]) [:data] = defaults[:data].deep_merge([:data] || {}) [:value] = @builder.object.public_send(attribute).presence [:value] = [:value].iso8601 if [:value].respond_to?(:iso8601) @builder.text_field(attribute, ) end |
#datetime_flatpickr(attribute, options = {}) ⇒ Object
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/super/form_builder/flatpickr_methods.rb', line 27 def datetime_flatpickr(attribute, = {}) , defaults = split_defaults( , class: "super-input w-full", data: { controller: "flatpickr", flatpickr_options_value: { enableSeconds: true, enableTime: true, dateFormat: "Z" } } ) [:class] = join_classes(defaults[:class], [:class]) [:data] = defaults[:data].deep_merge([:data] || {}) [:value] = @builder.object.public_send(attribute).presence [:value] = [:value].iso8601 if [:value].respond_to?(:iso8601) @builder.text_field(attribute, ) end |
#grouped_collection_select(attribute, collection, group_method, group_label_method, option_key_method, option_value_method, options = {}, html_options = {}) ⇒ Object
28 29 30 31 32 33 34 35 |
# File 'lib/super/form_builder/option_methods.rb', line 28 def grouped_collection_select(attribute, collection, group_method, group_label_method, option_key_method, option_value_method, = {}, = {}) , defaults = split_defaults(, include_blank: true) = defaults.merge() , html_defaults = split_defaults(, class: "super-input super-input-select") [:class] = join_classes(html_defaults[:class], [:class]) @builder.grouped_collection_select(attribute, collection, group_method, group_label_method, option_key_method, option_value_method, , ) end |
#hidden_field(attribute, options = {}) ⇒ Object
47 48 49 |
# File 'lib/super/form_builder/base_methods.rb', line 47 def hidden_field(attribute, = {}) @builder.hidden_field(attribute, ) end |
#inline_errors(attribute) ⇒ Object
34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/super/form_builder.rb', line 34 def inline_errors(attribute) if @builder.object = Form::InlineErrors.(@builder.object, attribute).map do |msg| error_content_tag(msg) end @template.safe_join() else error_content_tag(<<~MSG.html_safe) This form doesn't have an object, so something is probably wrong. Maybe <code>accepts_nested_attributes_for</code> isn't set up? MSG end end |
#label(attribute, text = nil, options = {}, &block) ⇒ Object
20 21 22 23 24 25 |
# File 'lib/super/form_builder/base_methods.rb', line 20 def label(attribute, text = nil, = {}, &block) , defaults = split_defaults(, class: "block") [:class] = join_classes(defaults[:class], [:class]) @builder.label(attribute, text, , &block) end |
#rich_text_area(attribute, options = {}) ⇒ Object
6 7 8 9 10 11 |
# File 'lib/super/form_builder/action_text_methods.rb', line 6 def rich_text_area(attribute, = {}) , defaults = split_defaults(, class: "trix-content super-input w-full") [:class] = join_classes(defaults[:class], [:class]) @builder.rich_text_area(attribute, ) end |
#select(attribute, choices, options = {}, html_options = {}, &block) ⇒ Object
6 7 8 9 10 11 12 13 |
# File 'lib/super/form_builder/option_methods.rb', line 6 def select(attribute, choices, = {}, = {}, &block) , defaults = split_defaults(, include_blank: true) = defaults.merge() , html_defaults = split_defaults(, class: "super-input super-input-select") [:class] = join_classes(html_defaults[:class], [:class]) @builder.select(attribute, choices, , , &block) end |
#submit(value = nil, options = {}) ⇒ Object
def radio_button(attribute, tag_value, label_text: nil, label: {}, field: {}, show_errors: true) end
58 59 60 61 62 63 64 |
# File 'lib/super/form_builder/base_methods.rb', line 58 def submit(value = nil, = {}) value, = nil, value if value.is_a?(Hash) , defaults = split_defaults(, class: "super-button") [:class] = join_classes(defaults[:class], [:class]) @builder.submit(value, ) end |
#time_flatpickr(attribute, options = {}) ⇒ Object
50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 |
# File 'lib/super/form_builder/flatpickr_methods.rb', line 50 def time_flatpickr(attribute, = {}) , defaults = split_defaults( , class: "super-input w-full", data: { controller: "flatpickr", flatpickr_options_value: { enableSeconds: true, enableTime: true, noCalendar: true, dateFormat: "H:i:S" } } ) [:class] = join_classes(defaults[:class], [:class]) [:data] = defaults[:data].deep_merge([:data] || {}) [:value] = @builder.object.public_send(attribute).presence [:value] = [:value].strftime("%H:%M:%S") if [:value].respond_to?(:strftime) @builder.text_field(attribute, ) end |
#time_zone_select(attribute, priority_zones = nil, options = {}, html_options = {}) ⇒ Object
39 40 41 42 43 44 45 46 |
# File 'lib/super/form_builder/option_methods.rb', line 39 def time_zone_select(attribute, priority_zones = nil, = {}, = {}) , defaults = split_defaults(, include_blank: true) = defaults.merge() , html_defaults = split_defaults(, class: "super-input super-input-select") [:class] = join_classes(html_defaults[:class], [:class]) @builder.time_zone_select(attribute, priority_zones, , ) end |