Class: BootstrapForm::FormBuilder

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from FormGroup

#form_group

Methods included from Helpers::Bootstrap

#alert_message, #button, #custom_control, #error_summary, #errors_on, #input_group_content, #input_with_error, #prepend_and_append_input, #primary, #static_class, #static_control, #submit

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
61
62
63
64
# File 'lib/bootstrap_form/form_builder.rb', line 50

def initialize(object_name, object, template, 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 = if options[:inline_errors].nil?
                     @label_errors != true
                   else
                     options[:inline_errors] != false
                   end
  @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.



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

def acts_like_form_tag
  @acts_like_form_tag
end

#control_colObject (readonly)

Returns the value of attribute control_col.



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

def control_col
  @control_col
end

#has_errorObject (readonly)

Returns the value of attribute has_error.



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

def has_error
  @has_error
end

#inline_errorsObject (readonly)

Returns the value of attribute inline_errors.



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

def inline_errors
  @inline_errors
end

#label_colObject (readonly)

Returns the value of attribute label_col.



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

def label_col
  @label_col
end

#label_errorsObject (readonly)

Returns the value of attribute label_errors.



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

def label_errors
  @label_errors
end

#layoutObject (readonly)

Returns the value of attribute layout.



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

def layout
  @layout
end

Instance Method Details

#add_default_form_attributes_and_form_inline(options) ⇒ Object



66
67
68
69
70
71
72
73
74
75
# File 'lib/bootstrap_form/form_builder.rb', line 66

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



77
78
79
80
81
# File 'lib/bootstrap_form/form_builder.rb', line 77

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