Class: PandaCms::FormBuilder
- Inherits:
-
ActionView::Helpers::FormBuilder
- Object
- ActionView::Helpers::FormBuilder
- PandaCms::FormBuilder
- Includes:
- ActionView::Helpers::TagHelper
- Defined in:
- app/builders/panda_cms/form_builder.rb
Instance Method Summary collapse
-
#button(value = nil, options = {}, &block) ⇒ Object
> 7.1.3.
- #check_box(method, options = {}, checked_value = "1", unchecked_value = "0") ⇒ Object
- #collection_select(method, collection, value_method, text_method, options = {}, html_options = {}) ⇒ Object
- #date_field(method, options = {}) ⇒ Object
- #datetime_field(attribute, options = {}) ⇒ Object
- #email_field(attribute, options = {}) ⇒ Object
- #file_field(method, options = {}) ⇒ Object
- #label(attribute, text = nil, options = {}, &block) ⇒ Object
- #meta_text(options) ⇒ Object
- #password_field(attribute, options = {}) ⇒ Object
- #rich_text_area(method, options = {}) ⇒ Object
- #rich_text_field(method, options = {}) ⇒ Object
- #select(method, choices = nil, options = {}, html_options = {}, &block) ⇒ Object
-
#submit(value = nil, options = {}) ⇒ Object
> 7.1.3.
- #text_area(method, options = {}) ⇒ Object
- #text_field(attribute, options = {}) ⇒ Object
- #time_zone_select(method, priority_zones = nil, options = {}, html_options = {}) ⇒ Object
Instance Method Details
#button(value = nil, options = {}, &block) ⇒ Object
> 7.1.3
73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 |
# File 'app/builders/panda_cms/form_builder.rb', line 73 def (value = nil, = {}, &block) # => 7.1.3 case value when Hash value, = nil, value when Symbol value, = nil, {name: field_name(value), id: field_id(value)}.merge!(.to_h) end value ||= submit_default_value formmethod = [:formmethod] if formmethod.present? && !/post|get/i.match?(formmethod) && !.key?(:name) && !.key?(:value) .merge! formmethod: :post, name: "_method", value: formmethod end value = if block @template.capture { yield(value) } else content_tag(:i, "", class: "fa-sharp fa-circle-check mr-1 pt-[0.2rem]") + value end @template.(value, .reverse_merge(class: )) end |
#check_box(method, options = {}, checked_value = "1", unchecked_value = "0") ⇒ Object
100 101 102 103 104 |
# File 'app/builders/panda_cms/form_builder.rb', line 100 def check_box(method, = {}, checked_value = "1", unchecked_value = "0") content_tag :div, class: container_styles do label(method) + () + super(method, .reverse_merge(class: "border-gray-300 ml-2"), checked_value, unchecked_value) end end |
#collection_select(method, collection, value_method, text_method, options = {}, html_options = {}) ⇒ Object
55 56 57 58 59 |
# File 'app/builders/panda_cms/form_builder.rb', line 55 def collection_select(method, collection, value_method, text_method, = {}, = {}) content_tag :div, class: container_styles do label(method) + () + super(method, collection, value_method, text_method, , .reverse_merge(class: input_styles)) end end |
#date_field(method, options = {}) ⇒ Object
106 107 108 109 110 |
# File 'app/builders/panda_cms/form_builder.rb', line 106 def date_field(method, = {}) content_tag :div, class: container_styles do label(method) + () + super(method, .reverse_merge(class: input_styles)) end end |
#datetime_field(attribute, options = {}) ⇒ Object
31 32 33 34 35 |
# File 'app/builders/panda_cms/form_builder.rb', line 31 def datetime_field(attribute, = {}) content_tag :div, class: container_styles do label(attribute) + () + super(attribute, .reverse_merge(class: input_styles)) end end |
#email_field(attribute, options = {}) ⇒ Object
25 26 27 28 29 |
# File 'app/builders/panda_cms/form_builder.rb', line 25 def email_field(attribute, = {}) content_tag :div, class: container_styles do label(attribute) + () + super(attribute, .reverse_merge(class: input_styles)) end end |
#file_field(method, options = {}) ⇒ Object
67 68 69 70 71 |
# File 'app/builders/panda_cms/form_builder.rb', line 67 def file_field(method, = {}) content_tag :div, class: container_styles do label(method) + () + super(method, .reverse_merge(class: "file:rounded file:border-0 file:text-sm file:bg-white file:text-gray-500 hover:file:bg-gray-50 bg-white px-2.5 hover:bg-gray-50".concat(input_styles))) end end |
#label(attribute, text = nil, options = {}, &block) ⇒ Object
5 6 7 |
# File 'app/builders/panda_cms/form_builder.rb', line 5 def label(attribute, text = nil, = {}, &block) super(attribute, text, .reverse_merge(class: label_styles)) end |
#meta_text(options) ⇒ Object
124 125 126 127 128 |
# File 'app/builders/panda_cms/form_builder.rb', line 124 def () if [:meta] content_tag :span, [:meta], class: "block text-black/60 italic text-sm mb-2" end end |
#password_field(attribute, options = {}) ⇒ Object
43 44 45 46 47 |
# File 'app/builders/panda_cms/form_builder.rb', line 43 def password_field(attribute, = {}) content_tag :div, class: container_styles do label(attribute) + () + super(attribute, .reverse_merge(class: input_styles)) end end |
#rich_text_area(method, options = {}) ⇒ Object
112 113 114 115 116 |
# File 'app/builders/panda_cms/form_builder.rb', line 112 def rich_text_area(method, = {}) content_tag :div, class: container_styles do label(method) + () + super(method, .reverse_merge(class: textarea_styles)) end end |
#rich_text_field(method, options = {}) ⇒ Object
118 119 120 121 122 |
# File 'app/builders/panda_cms/form_builder.rb', line 118 def rich_text_field(method, = {}) content_tag :div, class: container_styles do label(method) + () + super(method, .reverse_merge(class: textarea_styles)) end end |
#select(method, choices = nil, options = {}, html_options = {}, &block) ⇒ Object
49 50 51 52 53 |
# File 'app/builders/panda_cms/form_builder.rb', line 49 def select(method, choices = nil, = {}, = {}, &block) content_tag :div, class: container_styles do label(method) + () + super(method, choices, , .reverse_merge(class: input_styles)) end end |
#submit(value = nil, options = {}) ⇒ Object
> 7.1.3
96 97 98 |
# File 'app/builders/panda_cms/form_builder.rb', line 96 def submit(value = nil, = {}) # => 7.1.3 super(value, .reverse_merge(class: )) end |
#text_area(method, options = {}) ⇒ Object
37 38 39 40 41 |
# File 'app/builders/panda_cms/form_builder.rb', line 37 def text_area(method, = {}) content_tag :div, class: container_styles do label(method) + () + super(method, .reverse_merge(class: input_styles)) end end |
#text_field(attribute, options = {}) ⇒ Object
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
# File 'app/builders/panda_cms/form_builder.rb', line 9 def text_field(attribute, = {}) if .dig(:data, :prefix) content_tag :div, class: container_styles do label(attribute) + () + content_tag(:div, class: "flex flex-grow") do content_tag(:span, class: "inline-flex items-center px-3 text-base border border-r-none rounded-s-md whitespace-nowrap break-keep") { .dig(:data, :prefix) } + super(attribute, .reverse_merge(class: input_styles_prefix + " input-prefix rounded-l-none border-l-none")) end end else content_tag :div, class: container_styles do label(attribute) + () + super(attribute, .reverse_merge(class: input_styles)) end end end |
#time_zone_select(method, priority_zones = nil, options = {}, html_options = {}) ⇒ Object
61 62 63 64 65 |
# File 'app/builders/panda_cms/form_builder.rb', line 61 def time_zone_select(method, priority_zones = nil, = {}, = {}) content_tag :div, class: container_styles do label(method) + () + super(method, priority_zones, , .reverse_merge(class: input_styles)) end end |