Class: NdrUi::BootstrapBuilder

Inherits:
ActionView::Helpers::FormBuilder
  • Object
show all
Includes:
NdrUi::Bootstrap::Datepicker, NdrUi::Bootstrap::ErrorAndWarningAlertBoxes, NdrUi::Bootstrap::FormControlClass, NdrUi::Bootstrap::InlineErrorsAndWarnings, NdrUi::Bootstrap::InputGroupAddons, NdrUi::Bootstrap::LabelTooltips, NdrUi::Bootstrap::Readonly, CssHelper
Defined in:
app/builders/ndr_ui/bootstrap_builder.rb

Overview

Our Bootstrp FormBuilder subclass

Constant Summary

Constants included from NdrUi::Bootstrap::ErrorAndWarningAlertBoxes

NdrUi::Bootstrap::ErrorAndWarningAlertBoxes::ALERT_BOX_TYPE, NdrUi::Bootstrap::ErrorAndWarningAlertBoxes::SAFE_BLANK_STRING

Instance Attribute Summary collapse

Attributes included from NdrUi::Bootstrap::Readonly

#readonly

Class Method Summary collapse

Instance Method Summary collapse

Methods included from NdrUi::Bootstrap::LabelTooltips

#label

Methods included from NdrUi::Bootstrap::ErrorAndWarningAlertBoxes

#base_issues, #error_alert_box, #error_and_warning_alert_boxes, #issue_alert_box, #issue_wrapper, #non_base_issues, #warning_alert_box

Methods included from NdrUi::Bootstrap::Datepicker

#datepicker_field

Methods included from NdrUi::Bootstrap::InlineErrorsAndWarnings

add_inline_errors_and_warnings_to_field_helper, included

Methods included from NdrUi::Bootstrap::InputGroupAddons

#text_field

Methods included from NdrUi::Bootstrap::Readonly

included, #initialize

Methods included from NdrUi::Bootstrap::FormControlClass

add_form_control_class, add_select_control_class

Methods included from CssHelper

#css_class_options_merge

Instance Attribute Details

#horizontal_modeObject

Returns the value of attribute horizontal_mode.



28
29
30
# File 'app/builders/ndr_ui/bootstrap_builder.rb', line 28

def horizontal_mode
  @horizontal_mode
end

Class Method Details

.all_known_field_helpersObject

FormBuilder defines ‘field_helpers`, but it is not an exhaustive list; here, add any others that we may want to be aware of.



6
7
8
# File 'app/builders/ndr_ui/bootstrap_builder.rb', line 6

def self.all_known_field_helpers
  field_helpers | field_helpers_from_form_options_helper | field_helpers_from_date_helper
end

.field_helpers_from_date_helperObject



15
16
17
# File 'app/builders/ndr_ui/bootstrap_builder.rb', line 15

def self.field_helpers_from_date_helper
  [:date_select, :time_select, :datetime_select]
end

.field_helpers_from_form_options_helperObject



10
11
12
13
# File 'app/builders/ndr_ui/bootstrap_builder.rb', line 10

def self.field_helpers_from_form_options_helper
  [:select, :collection_select, :grouped_collection_select,
   :time_zone_select, :collection_check_boxes, :collection_radio_buttons]
end

Instance Method Details

#control_group(methods, text = nil, options = {}, control_options = {}, controls = '', &block) ⇒ Object

<%= form.control_group(:title, ‘Demo’, => “col-md-6”, => ‘some_id’, “# Controls go here”) %>

# => <div class="form-group col-md-6">
        <label for="post_title" class="control-label">Demo</label>
        <div id="some_id">
          # Controls go here
        </div>
      </div>

You can use a block as well if your alert message is hard to fit into the message parameter. ERb example:

<%= form.control_group(:title, 'Demo', {:class => "col-md-6"}, {:id => 'some_id'}) do %>
  # Controls go here
<% end %>


65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
# File 'app/builders/ndr_ui/bootstrap_builder.rb', line 65

def control_group(methods, text = nil, options = {}, control_options = {}, controls = '', &block)
  if block_given?
    return control_group(methods, text, options, control_options, @template.capture(&block))
  else
    methods = [methods].compact unless methods.is_a?(Array)

    label_classes = ['control-label']
    label_classes << "col-md-#{label_columns}" if horizontal_mode
    label_options = {class: label_classes.join(' ')}
    label_options[:tooltip] = options.delete(:tooltip)
    label_html = if methods.present?
                   label(methods.first, text, label_options)
                 else
                   @template.(:span, text, class: label_classes.join(' '))
                 end

    control_options = css_class_options_merge(control_options) do |control_classes|
      # Only add a col-md-N class if none already specified
      if horizontal_mode && control_classes.none? { |css_class| css_class.start_with?('col-') }
        control_classes << "col-md-#{12 - label_columns}"
      end
    end

    @template.(:div,
                          label_html +
                            @template.(:div, controls, control_options),
                          control_group_options(methods, options))
  end
end

#label_columnsObject

if horizontal_mode is true the label_columns defaults to 3 columns



109
110
111
# File 'app/builders/ndr_ui/bootstrap_builder.rb', line 109

def label_columns
  horizontal_mode === true ? 3 : horizontal_mode
end