Class: RailsI18nManager::CustomFormBuilder
- Inherits:
-
ActionView::Helpers::FormBuilder
- Object
- ActionView::Helpers::FormBuilder
- RailsI18nManager::CustomFormBuilder
- Defined in:
- app/helpers/rails_i18n_manager/custom_form_builder.rb
Constant Summary collapse
- ALLOWED_OPTIONS =
[ :value, :name, :label, :field_wrapper_html, :label_wrapper_html, :label_html, :input_wrapper_html, :input_html, :required, :required_text, :help_text, :errors, :field_layout, :view_mode, ### SELECT OPTIONS :collection, :selected, :disabled, :prompt, :include_blank, ].freeze
Instance Method Summary collapse
- #error_notification ⇒ Object
- #field(method, type:, **options) ⇒ Object
- #view_field(label:, value:, **options) ⇒ Object
Instance Method Details
#error_notification ⇒ Object
28 29 30 |
# File 'app/helpers/rails_i18n_manager/custom_form_builder.rb', line 28 def error_notification @template.render "rails_i18n_manager/form_builder/error_notification", {f: self} end |
#field(method, type:, **options) ⇒ Object
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 |
# File 'app/helpers/rails_i18n_manager/custom_form_builder.rb', line 36 def field(method, type:, **) type = type.to_sym = (, method) if [:view_mode] return _view_field(method, type, ) end = .keys - ALLOWED_OPTIONS if .any? raise "Invalid options provided: #{.join(", ")}" end if [:select, :textarea].exclude?(type) [:input_html][:type] = type.to_s end case type when :select [:collection] = _fetch_required_option(:collection, ) = (, method) when :checkbox = (, method) else if ![:input_html].has_key?(:value) [:input_html][:value] = object.send(method) end end @template.render("rails_i18n_manager/form_builder/basic_field", { f: self, method: method, type: type, options: , }) end |
#view_field(label:, value:, **options) ⇒ Object
32 33 34 |
# File 'app/helpers/rails_i18n_manager/custom_form_builder.rb', line 32 def view_field(label:, value:, **) field(nil, type: :view, **.merge(label: label, value: value, view_mode: true)) end |