Class: BootstrapForm::FormBuilder

Instance Attribute 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.



50
51
52
53
54
55
56
57
58
59
60
# File 'lib/bootstrap_form/form_builder.rb', line 50

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.



5
6
7
# File 'lib/bootstrap_form/form_builder.rb', line 5

def acts_like_form_tag
  @acts_like_form_tag
end

#control_colObject (readonly)

Returns the value of attribute control_col.



5
6
7
# File 'lib/bootstrap_form/form_builder.rb', line 5

def control_col
  @control_col
end

#has_errorObject (readonly)

Returns the value of attribute has_error.



5
6
7
# File 'lib/bootstrap_form/form_builder.rb', line 5

def has_error
  @has_error
end

#inline_errorsObject (readonly)

Returns the value of attribute inline_errors.



5
6
7
# File 'lib/bootstrap_form/form_builder.rb', line 5

def inline_errors
  @inline_errors
end

#label_colObject (readonly)

Returns the value of attribute label_col.



5
6
7
# File 'lib/bootstrap_form/form_builder.rb', line 5

def label_col
  @label_col
end

#label_errorsObject (readonly)

Returns the value of attribute label_errors.



5
6
7
# File 'lib/bootstrap_form/form_builder.rb', line 5

def label_errors
  @label_errors
end

#layoutObject (readonly)

Returns the value of attribute layout.



5
6
7
# File 'lib/bootstrap_form/form_builder.rb', line 5

def layout
  @layout
end

Instance Method Details

#add_default_form_attributes_and_form_inline(options) ⇒ Object



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

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] =
    ([*options[:html][:class]&.split(/\s+/)] + %w[row row-cols-auto g-3 align-items-center])
    .compact.uniq.join(" ")
end

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



73
74
75
76
77
# File 'lib/bootstrap_form/form_builder.rb', line 73

def fields_for_with_bootstrap(record_name, record_object=nil, fields_options={}, &block)
  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, &block)
end