Class: DefaultForm::FormBuilder
- Inherits:
-
ActionView::Helpers::FormBuilder
- Object
- ActionView::Helpers::FormBuilder
- DefaultForm::FormBuilder
- Includes:
- Builder::Helper
- Defined in:
- lib/default_form/form_builder.rb
Constant Summary
Constants included from Builder::Helper
Constants included from Builder::Default
Instance Attribute Summary collapse
-
#error_css ⇒ Object
readonly
Returns the value of attribute error_css.
-
#offset_css ⇒ Object
readonly
Returns the value of attribute offset_css.
-
#on_options ⇒ Object
readonly
Returns the value of attribute on_options.
-
#origin_css ⇒ Object
readonly
Returns the value of attribute origin_css.
-
#params ⇒ Object
readonly
Returns the value of attribute params.
-
#theme ⇒ Object
readonly
Returns the value of attribute theme.
-
#wrap_css ⇒ Object
readonly
Returns the value of attribute wrap_css.
Instance Method Summary collapse
-
#initialize(object_name, object, template, options) ⇒ FormBuilder
constructor
A new instance of FormBuilder.
- #submit_default_value ⇒ Object
Methods included from Builder::Helper
#check_box, #collection_check_boxes, #collection_radio_buttons, #collection_select, #date_field, #fields, #hidden_field, #label, #number_field, #radio_button, #select, #submit, #text_area, #time_select, #time_zone_select, #wrap_all_with, #wrap_with
Methods included from Builder::Default
#default_help, #default_label, #default_options, #default_step, #default_value, #default_without_method
Methods included from Builder::Wrap
#help_tag, #object_has_errors?, #offset, #wrapping, #wrapping_all
Constructor Details
#initialize(object_name, object, template, options) ⇒ FormBuilder
Returns a new instance of FormBuilder.
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/default_form/form_builder.rb', line 13 def initialize(object_name, object, template, ) if .key?(:theme) @theme = [:theme].to_s else @theme = 'default' end set_file = Rails.root.join('config/default_form.yml').existence || RailsCom::Engine.root.join('config/default_form.yml') set = YAML.load_file set_file settings = set.fetch(theme, {}) settings.deep_symbolize_keys! [:method] = settings[:method] if !.key?(:method) && settings.key?(:method) [:local] = true # todo rails 6.2 will remove this [:data] ||= {} if [:data][:controller].present? [:data][:controller] += ' default_valid' else [:data][:controller] = 'default_valid' end @origin_css = settings.fetch(:origin, {}).merge .fetch(:origin, {}) @wrap_css = settings.fetch(:wrap, {}).merge .fetch(:wrap, {}) @error_css = settings.fetch(:error, {}).merge .fetch(:error, {}) @offset_css = settings.fetch(:offset, {}).merge .fetch(:offset, {}) @on_options = settings.extract! :autocomplete, :autofilter, :placeholder, :label @on_options.merge! .slice(:placeholder, :label, :autocomplete, :autofilter) @params = template.params _values = Hash(params.permit(object_name => {})[object_name]) if object.is_a?(ActiveRecord::Base) object.assign_attributes _values.slice(*object.attribute_names) end if [:class].to_s.start_with?('new_', 'edit_') [:class] = origin_css[:form] end [:class] = origin_css[:form] unless .key?(:class) super end |
Instance Attribute Details
#error_css ⇒ Object (readonly)
Returns the value of attribute error_css.
10 11 12 |
# File 'lib/default_form/form_builder.rb', line 10 def error_css @error_css end |
#offset_css ⇒ Object (readonly)
Returns the value of attribute offset_css.
10 11 12 |
# File 'lib/default_form/form_builder.rb', line 10 def offset_css @offset_css end |
#on_options ⇒ Object (readonly)
Returns the value of attribute on_options.
10 11 12 |
# File 'lib/default_form/form_builder.rb', line 10 def @on_options end |
#origin_css ⇒ Object (readonly)
Returns the value of attribute origin_css.
10 11 12 |
# File 'lib/default_form/form_builder.rb', line 10 def origin_css @origin_css end |
#params ⇒ Object (readonly)
Returns the value of attribute params.
10 11 12 |
# File 'lib/default_form/form_builder.rb', line 10 def params @params end |
#theme ⇒ Object (readonly)
Returns the value of attribute theme.
10 11 12 |
# File 'lib/default_form/form_builder.rb', line 10 def theme @theme end |
#wrap_css ⇒ Object (readonly)
Returns the value of attribute wrap_css.
10 11 12 |
# File 'lib/default_form/form_builder.rb', line 10 def wrap_css @wrap_css end |
Instance Method Details
#submit_default_value ⇒ Object
54 55 56 57 58 |
# File 'lib/default_form/form_builder.rb', line 54 def submit_default_value I18n.t "helpers.submit.#{theme}", raise: true rescue super end |