Class: BootstrapForm::FormBuilder

Overview

rubocop:disable Metrics/ClassLength

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Inputs::Submit

#button, #primary, #submit

Methods included from FormGroup

#form_group

Methods included from Helpers::Bootstrap

#alert_message, #custom_control, #error_summary, #errors_on, #input_group_content, #input_with_error, #prepend_and_append_input, #static_class, #static_control

Methods included from Helpers::Field

#required_field_options

Constructor Details

#initialize(object_name, object, template, options) ⇒ FormBuilder

Returns a new instance of FormBuilder.



60
61
62
63
64
65
66
67
68
69
70
# File 'lib/bootstrap_form/form_builder.rb', line 60

def initialize(object_name, object, template, options)
  warn_deprecated_layout_value(options)
  @layout = options[:layout] || default_layout
  @label_col = options[:label_col] || default_label_col
  @control_col = options[:control_col] || default_control_col
  @label_errors = options[:label_errors] || false
  @inline_errors = options[:inline_errors].nil? ? @label_errors != true : options[:inline_errors] != false
  @acts_like_form_tag = options[:acts_like_form_tag]
  add_default_form_attributes_and_form_inline options
  super
end

Instance Attribute Details

#acts_like_form_tagObject (readonly)

Returns the value of attribute acts_like_form_tag.



7
8
9
# File 'lib/bootstrap_form/form_builder.rb', line 7

def acts_like_form_tag
  @acts_like_form_tag
end

#control_colObject (readonly)

Returns the value of attribute control_col.



7
8
9
# File 'lib/bootstrap_form/form_builder.rb', line 7

def control_col
  @control_col
end

#has_errorObject (readonly)

Returns the value of attribute has_error.



7
8
9
# File 'lib/bootstrap_form/form_builder.rb', line 7

def has_error
  @has_error
end

#inline_errorsObject (readonly)

Returns the value of attribute inline_errors.



7
8
9
# File 'lib/bootstrap_form/form_builder.rb', line 7

def inline_errors
  @inline_errors
end

#label_colObject (readonly)

Returns the value of attribute label_col.



7
8
9
# File 'lib/bootstrap_form/form_builder.rb', line 7

def label_col
  @label_col
end

#label_errorsObject (readonly)

Returns the value of attribute label_errors.



7
8
9
# File 'lib/bootstrap_form/form_builder.rb', line 7

def label_errors
  @label_errors
end

#layoutObject (readonly)

Returns the value of attribute layout.



7
8
9
# File 'lib/bootstrap_form/form_builder.rb', line 7

def layout
  @layout
end

Class Method Details

.redefine_rich_text_area?Boolean

Returns:

  • (Boolean)


11
12
13
# File 'lib/bootstrap_form/form_builder.rb', line 11

def redefine_rich_text_area?
  ActionView::Helpers::FormBuilder.instance_methods.any? { _1 == :rich_text_area }
end

Instance Method Details

#add_default_form_attributes_and_form_inline(options) ⇒ Object



72
73
74
75
76
77
78
79
80
81
# File 'lib/bootstrap_form/form_builder.rb', line 72

def add_default_form_attributes_and_form_inline(options)
  options[:html] ||= {}
  options[:html].reverse_merge!(BootstrapForm.config.default_form_attributes)

  return unless options[:layout] == :inline

  options[:html][:class] =
    safe_join(([*options[:html][:class]&.split(/\s+/)] + %w[row row-cols-auto g-3 align-items-center])
    .compact.uniq, " ")
end

#fields_for_with_bootstrap(record_name, record_object = nil, fields_options = {}) ⇒ Object



83
84
85
86
87
# File 'lib/bootstrap_form/form_builder.rb', line 83

def fields_for_with_bootstrap(record_name, record_object=nil, fields_options={}, &)
  fields_options = fields_for_options(record_object, fields_options)
  record_object = nil if record_object.is_a?(Hash) && record_object.extractable_options?
  fields_for_without_bootstrap(record_name, record_object, fields_options, &)
end