Class: NdrUi::BootstrapBuilder
- Inherits:
-
ActionView::Helpers::FormBuilder
- Object
- ActionView::Helpers::FormBuilder
- NdrUi::BootstrapBuilder
- 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
-
#horizontal_mode ⇒ Object
Returns the value of attribute horizontal_mode.
Attributes included from NdrUi::Bootstrap::Readonly
Class Method Summary collapse
-
.all_known_field_helpers ⇒ Object
FormBuilder defines ‘field_helpers`, but it is not an exhaustive list; here, add any others that we may want to be aware of.
- .field_helpers_from_date_helper ⇒ Object
- .field_helpers_from_form_options_helper ⇒ Object
Instance Method Summary collapse
-
#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>.
-
#label_columns ⇒ Object
if horizontal_mode is true the label_columns defaults to 3 columns.
Methods included from NdrUi::Bootstrap::LabelTooltips
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
Methods included from NdrUi::Bootstrap::InlineErrorsAndWarnings
add_inline_errors_and_warnings_to_field_helper, included
Methods included from NdrUi::Bootstrap::InputGroupAddons
Methods included from NdrUi::Bootstrap::Readonly
Methods included from NdrUi::Bootstrap::FormControlClass
add_form_control_class, add_select_control_class
Methods included from CssHelper
Instance Attribute Details
#horizontal_mode ⇒ Object
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_helpers ⇒ Object
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_date_helper end |
.field_helpers_from_date_helper ⇒ Object
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_helper ⇒ Object
10 11 12 13 |
# File 'app/builders/ndr_ui/bootstrap_builder.rb', line 10 def self. [: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, = {}, = {}, controls = '', &block) if block_given? return control_group(methods, text, , , @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 = {class: label_classes.join(' ')} [:tooltip] = .delete(:tooltip) label_html = if methods.present? label(methods.first, text, ) else @template.content_tag(:span, text, class: label_classes.join(' ')) end = () 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.content_tag(:div, label_html + @template.content_tag(:div, controls, ), (methods, )) end end |
#label_columns ⇒ Object
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 |