Class: ViewPartialFormBuilder::FormBuilder
- Inherits:
-
ActionView::Helpers::FormBuilder
- Object
- ActionView::Helpers::FormBuilder
- ViewPartialFormBuilder::FormBuilder
- Defined in:
- lib/view_partial_form_builder/form_builder.rb
Constant Summary collapse
- DYNAMICALLY_DECLARED =
( field_helpers + [:rich_text_area] - [:label, :check_box, :radio_button, :fields_for, :fields, :hidden_field, :file_field] )
Instance Attribute Summary collapse
-
#default ⇒ Object
readonly
Returns the value of attribute default.
Instance Method Summary collapse
- #button(value = nil, **options) ⇒ Object
- #check_box(method, options = {}, checked_value = "1", unchecked_value = "0") ⇒ Object
- #collection_check_boxes(method, collection, value_method, text_method, options = {}, **html_options, &block) ⇒ Object
- #collection_radio_buttons(method, collection, value_method, text_method, options = {}, **html_options, &block) ⇒ Object
- #collection_select(method, collection, value_method, text_method, options = {}, **html_options) ⇒ Object
- #date_select(method, options = {}, **html_options) ⇒ Object
- #file_field(method, **options) ⇒ Object
- #grouped_collection_select(method, collection, group_method, group_label_method, option_key_method, option_value_method, options = {}, **html_options) ⇒ Object
- #hidden_field(method, **options) ⇒ Object
-
#initialize ⇒ FormBuilder
constructor
A new instance of FormBuilder.
- #label(method, text = nil, **options, &block) ⇒ Object
- #radio_button(method, tag_value, **options) ⇒ Object
- #select(method, choices = nil, options = {}, **html_options, &block) ⇒ Object
- #submit(value = nil, **options) ⇒ Object
- #time_zone_select(method, priority_zones = nil, options = {}, **html_options) ⇒ Object
Constructor Details
#initialize ⇒ FormBuilder
Returns a new instance of FormBuilder.
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
# File 'lib/view_partial_form_builder/form_builder.rb', line 8 def initialize(*) super @default = ActionView::Helpers::FormBuilder.new( object_name, object, @template, , ) @lookup_override = LookupOverride.new( prefixes: @template.lookup_context.prefixes, object_name: object&.model_name || object_name, view_partial_directory: ViewPartialFormBuilder.view_partial_directory, ) end |
Instance Attribute Details
#default ⇒ Object (readonly)
Returns the value of attribute default.
6 7 8 |
# File 'lib/view_partial_form_builder/form_builder.rb', line 6 def default @default end |
Instance Method Details
#button(value = nil, **options) ⇒ Object
224 225 226 227 228 229 230 231 232 233 234 235 |
# File 'lib/view_partial_form_builder/form_builder.rb', line 224 def (value = nil, **) value, = nil, value if value.is_a?(Hash) value ||= submit_default_value locals = { value: value, options: HtmlAttributes.new(), arguments: [value], } render_partial("button", locals, fallback: -> { super }) end |
#check_box(method, options = {}, checked_value = "1", unchecked_value = "0") ⇒ Object
36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/view_partial_form_builder/form_builder.rb', line 36 def check_box(method, = {}, checked_value = "1", unchecked_value = "0") locals = { method: method, options: HtmlAttributes.new(), checked_value: checked_value, unchecked_value: unchecked_value, arguments: [method, , checked_value, unchecked_value], } render_partial("check_box", locals, fallback: -> { super }) end |
#collection_check_boxes(method, collection, value_method, text_method, options = {}, **html_options, &block) ⇒ Object
90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 |
# File 'lib/view_partial_form_builder/form_builder.rb', line 90 def collection_check_boxes(method, collection, value_method, text_method, = {}, **, &block) = @default_html_options.merge() locals = { method: method, collection: collection, value_method: value_method, text_method: text_method, options: , html_options: HtmlAttributes.new(), block: block, arguments: [ method, collection, value_method, text_method, , ], } render_partial("collection_check_boxes", locals, fallback: -> { super }, &block) end |
#collection_radio_buttons(method, collection, value_method, text_method, options = {}, **html_options, &block) ⇒ Object
113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 |
# File 'lib/view_partial_form_builder/form_builder.rb', line 113 def (method, collection, value_method, text_method, = {}, **, &block) = @default_html_options.merge() locals = { method: method, collection: collection, value_method: value_method, text_method: text_method, options: , html_options: HtmlAttributes.new(), block: block, arguments: [ method, collection, value_method, text_method, , ], } render_partial("collection_radio_buttons", locals, fallback: -> { super }, &block) end |
#collection_select(method, collection, value_method, text_method, options = {}, **html_options) ⇒ Object
74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 |
# File 'lib/view_partial_form_builder/form_builder.rb', line 74 def collection_select(method, collection, value_method, text_method, = {}, **) = @default_html_options.merge() locals = { method: method, collection: collection, value_method: value_method, text_method: text_method, options: , html_options: , arguments: [method, collection, value_method, text_method, ], } render_partial("collection_select", locals, fallback: -> { super }) end |
#date_select(method, options = {}, **html_options) ⇒ Object
176 177 178 179 180 181 182 183 184 185 |
# File 'lib/view_partial_form_builder/form_builder.rb', line 176 def date_select(method, = {}, **) locals = { method: method, options: , html_options: HtmlAttributes.new(), arguments: [method, , ], } render_partial("date_select", locals, fallback: -> { super }) end |
#file_field(method, **options) ⇒ Object
199 200 201 202 203 204 205 206 207 208 209 |
# File 'lib/view_partial_form_builder/form_builder.rb', line 199 def file_field(method, **) self.multipart = true locals = { method: method, options: HtmlAttributes.new(), arguments: [method], } render_partial("file_field", locals, fallback: -> { super }) end |
#grouped_collection_select(method, collection, group_method, group_label_method, option_key_method, option_value_method, options = {}, **html_options) ⇒ Object
136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 |
# File 'lib/view_partial_form_builder/form_builder.rb', line 136 def grouped_collection_select(method, collection, group_method, group_label_method, option_key_method, option_value_method, = {}, **) = @default_html_options.merge() locals = { method: method, collection: collection, group_method: group_method, group_label_method: group_label_method, option_key_method: option_key_method, option_value_method: option_value_method, html_options: HtmlAttributes.new(), options: , arguments: [ method, collection, group_method, group_label_method, option_key_method, option_value_method, , ], } render_partial("grouped_collection_select", locals, fallback: -> { super }) end |
#hidden_field(method, **options) ⇒ Object
187 188 189 190 191 192 193 194 195 196 197 |
# File 'lib/view_partial_form_builder/form_builder.rb', line 187 def hidden_field(method, **) @emitted_hidden_id = true if method == :id locals = { method: method, options: HtmlAttributes.new(), arguments: [method], } render_partial("hidden_field", locals, fallback: -> { super }) end |
#label(method, text = nil, **options, &block) ⇒ Object
24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/view_partial_form_builder/form_builder.rb', line 24 def label(method, text = nil, **, &block) locals = { method: method, text: text, options: HtmlAttributes.new(), block: block, arguments: [method, text], } render_partial("label", locals, fallback: -> { super }, &block) end |
#radio_button(method, tag_value, **options) ⇒ Object
48 49 50 51 52 53 54 55 56 57 |
# File 'lib/view_partial_form_builder/form_builder.rb', line 48 def (method, tag_value, **) locals = { method: method, tag_value: tag_value, options: HtmlAttributes.new(), arguments: [method, tag_value], } render_partial("radio_button", locals, fallback: -> { super }) end |
#select(method, choices = nil, options = {}, **html_options, &block) ⇒ Object
59 60 61 62 63 64 65 66 67 68 69 70 71 72 |
# File 'lib/view_partial_form_builder/form_builder.rb', line 59 def select(method, choices = nil, = {}, **, &block) = @default_html_options.merge() locals = { method: method, choices: choices, options: , html_options: HtmlAttributes.new(), block: block, arguments: [method, choices, ], } render_partial("select", locals, fallback: -> { super }, &block) end |
#submit(value = nil, **options) ⇒ Object
211 212 213 214 215 216 217 218 219 220 221 222 |
# File 'lib/view_partial_form_builder/form_builder.rb', line 211 def submit(value = nil, **) value, = nil, value if value.is_a?(Hash) value ||= submit_default_value locals = { value: value, options: HtmlAttributes.new(), arguments: [value], } render_partial("submit", locals, fallback: -> { super }) end |
#time_zone_select(method, priority_zones = nil, options = {}, **html_options) ⇒ Object
162 163 164 165 166 167 168 169 170 171 172 173 174 |
# File 'lib/view_partial_form_builder/form_builder.rb', line 162 def time_zone_select(method, priority_zones = nil, = {}, **) = @default_html_options.merge() locals = { method: method, priority_zones: priority_zones, html_options: HtmlAttributes.new(), options: , arguments: [method, priority_zones, ], } render_partial("time_zone_select", locals, fallback: -> { super }) end |