Class: BootstrapForm::FormBuilder
- Inherits:
-
ActionView::Helpers::FormBuilder
- Object
- ActionView::Helpers::FormBuilder
- BootstrapForm::FormBuilder
- Includes:
- Helpers::Bootstrap
- Defined in:
- lib/bootstrap_form/form_builder.rb
Constant Summary collapse
- FIELD_HELPERS =
%w{color_field date_field datetime_field datetime_local_field email_field month_field number_field password_field phone_field range_field search_field telephone_field text_area text_field time_field url_field week_field}- DATE_SELECT_HELPERS =
%w{date_select time_select datetime_select}
Instance Attribute Summary collapse
-
#acts_like_form_tag ⇒ Object
readonly
Returns the value of attribute acts_like_form_tag.
-
#control_col ⇒ Object
readonly
Returns the value of attribute control_col.
-
#has_error ⇒ Object
readonly
Returns the value of attribute has_error.
-
#inline_errors ⇒ Object
readonly
Returns the value of attribute inline_errors.
-
#label_col ⇒ Object
readonly
Returns the value of attribute label_col.
-
#label_errors ⇒ Object
readonly
Returns the value of attribute label_errors.
-
#layout ⇒ Object
readonly
Returns the value of attribute layout.
Instance Method Summary collapse
- #check_box_with_bootstrap(name, options = {}, checked_value = "1", unchecked_value = "0", &block) ⇒ Object
- #check_boxes_collection(*args) ⇒ Object
- #collection_check_boxes(*args) ⇒ Object
- #collection_radio_buttons(*args) ⇒ Object
- #collection_select_with_bootstrap(method, collection, value_method, text_method, options = {}, html_options = {}) ⇒ Object
- #fields_for_with_bootstrap(record_name, record_object = nil, fields_options = {}, &block) ⇒ Object
- #file_field_with_bootstrap(name, options = {}) ⇒ Object
- #form_group(*args, &block) ⇒ Object
- #grouped_collection_select_with_bootstrap(method, collection, group_method, group_label_method, option_key_method, option_value_method, options = {}, html_options = {}) ⇒ Object
-
#initialize(object_name, object, template, options) ⇒ FormBuilder
constructor
A new instance of FormBuilder.
- #radio_button_with_bootstrap(name, value, *args) ⇒ Object
- #radio_buttons_collection(*args) ⇒ Object
- #select_with_bootstrap(method, choices, options = {}, html_options = {}) ⇒ Object
- #time_zone_select_with_bootstrap(method, priority_zones = nil, options = {}, html_options = {}) ⇒ Object
Methods included from Helpers::Bootstrap
#alert_message, #error_summary, #errors_on, #input_group_class, #prepend_and_append_input, #primary, #static_class, #static_control, #submit
Constructor Details
#initialize(object_name, object, template, options) ⇒ FormBuilder
Returns a new instance of FormBuilder.
18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/bootstrap_form/form_builder.rb', line 18 def initialize(object_name, object, template, ) @layout = [:layout] @label_col = [:label_col] || default_label_col @control_col = [:control_col] || default_control_col @label_errors = [:label_errors] || false @inline_errors = if [:inline_errors].nil? @label_errors != true else [:inline_errors] != false end @acts_like_form_tag = [:acts_like_form_tag] super end |
Instance Attribute Details
#acts_like_form_tag ⇒ Object (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_col ⇒ Object (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_error ⇒ Object (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_errors ⇒ Object (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_col ⇒ Object (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_errors ⇒ Object (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 |
#layout ⇒ Object (readonly)
Returns the value of attribute layout.
7 8 9 |
# File 'lib/bootstrap_form/form_builder.rb', line 7 def layout @layout end |
Instance Method Details
#check_box_with_bootstrap(name, options = {}, checked_value = "1", unchecked_value = "0", &block) ⇒ Object
101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 |
# File 'lib/bootstrap_form/form_builder.rb', line 101 def check_box_with_bootstrap(name, = {}, checked_value = "1", unchecked_value = "0", &block) = .symbolize_keys! = .except(:label, :label_class, :help, :inline) html = check_box_without_bootstrap(name, , checked_value, unchecked_value) label_content = block_given? ? capture(&block) : [:label] html.concat(" ").concat(label_content || (object && object.class.human_attribute_name(name)) || name.to_s.humanize) label_name = name label_name = "#{name}_#{checked_value}" if [:multiple] disabled_class = " disabled" if [:disabled] label_class = [:label_class] if [:inline] label_class = " #{label_class}" if label_class label(label_name, html, class: "checkbox-inline#{disabled_class}#{label_class}") else content_tag(:div, class: "checkbox#{disabled_class}") do label(label_name, html, class: label_class) end end end |
#check_boxes_collection(*args) ⇒ Object
162 163 164 165 |
# File 'lib/bootstrap_form/form_builder.rb', line 162 def check_boxes_collection(*args) warn "'BootstrapForm#check_boxes_collection' is deprecated, use 'BootstrapForm#collection_check_boxes' instead" collection_check_boxes(*args) end |
#collection_check_boxes(*args) ⇒ Object
148 149 150 151 152 153 154 |
# File 'lib/bootstrap_form/form_builder.rb', line 148 def collection_check_boxes(*args) html = inputs_collection(*args) do |name, value, | [:multiple] = true check_box(name, , value, nil) end hidden_field(args.first,{value: "", multiple: true}).concat(html) end |
#collection_radio_buttons(*args) ⇒ Object
156 157 158 159 160 |
# File 'lib/bootstrap_form/form_builder.rb', line 156 def (*args) inputs_collection(*args) do |name, value, | (name, value, ) end end |
#collection_select_with_bootstrap(method, collection, value_method, text_method, options = {}, html_options = {}) ⇒ Object
77 78 79 80 81 |
# File 'lib/bootstrap_form/form_builder.rb', line 77 def collection_select_with_bootstrap(method, collection, value_method, text_method, = {}, = {}) form_group_builder(method, , ) do collection_select_without_bootstrap(method, collection, value_method, text_method, , ) end end |
#fields_for_with_bootstrap(record_name, record_object = nil, fields_options = {}, &block) ⇒ Object
199 200 201 202 203 204 205 206 207 |
# File 'lib/bootstrap_form/form_builder.rb', line 199 def fields_for_with_bootstrap(record_name, record_object = nil, = {}, &block) , record_object = record_object, nil if record_object.is_a?(Hash) && record_object. [:layout] ||= [:layout] [:label_col] = [:label_col].present? ? "#{fields_options[:label_col]} #{label_class}" : [:label_col] [:control_col] ||= [:control_col] [:inline_errors] ||= [:inline_errors] [:label_errors] ||= [:label_errors] fields_for_without_bootstrap(record_name, record_object, , &block) end |
#file_field_with_bootstrap(name, options = {}) ⇒ Object
61 62 63 64 65 |
# File 'lib/bootstrap_form/form_builder.rb', line 61 def file_field_with_bootstrap(name, = {}) form_group_builder(name, .reverse_merge(control_class: nil)) do file_field_without_bootstrap(name, ) end end |
#form_group(*args, &block) ⇒ Object
172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 |
# File 'lib/bootstrap_form/form_builder.rb', line 172 def form_group(*args, &block) = args. name = args.first [:class] = ["form-group", [:class]].compact.join(' ') [:class] << " #{error_class}" if has_error?(name) [:class] << " #{feedback_class}" if [:icon] content_tag(:div, .except(:id, :label, :help, :icon, :label_col, :control_col, :layout)) do label = generate_label([:id], name, [:label], [:label_col], [:layout]) if [:label] control = capture(&block).to_s control.concat(generate_help(name, [:help]).to_s) control.concat(generate_icon([:icon])) if [:icon] if get_group_layout([:layout]) == :horizontal control_class = ([:control_col] || control_col.clone) unless [:label] control_offset = offset_col(/([0-9]+)$/.match([:label_col] || @label_col)) control_class.concat(" #{control_offset}") end control = content_tag(:div, control, class: control_class) end concat(label).concat(control) end end |
#grouped_collection_select_with_bootstrap(method, collection, group_method, group_label_method, option_key_method, option_value_method, options = {}, html_options = {}) ⇒ Object
85 86 87 88 89 |
# File 'lib/bootstrap_form/form_builder.rb', line 85 def grouped_collection_select_with_bootstrap(method, collection, group_method, group_label_method, option_key_method, option_value_method, = {}, = {}) form_group_builder(method, , ) do grouped_collection_select_without_bootstrap(method, collection, group_method, group_label_method, option_key_method, option_value_method, , ) end end |
#radio_button_with_bootstrap(name, value, *args) ⇒ Object
127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 |
# File 'lib/bootstrap_form/form_builder.rb', line 127 def (name, value, *args) = args..symbolize_keys! args << .except(:label, :label_class, :help, :inline) html = (name, value, *args) + " " + [:label] disabled_class = " disabled" if [:disabled] label_class = [:label_class] if [:inline] label_class = " #{label_class}" if label_class label(name, html, class: "radio-inline#{disabled_class}#{label_class}", value: value) else content_tag(:div, class: "radio#{disabled_class}") do label(name, html, value: value, class: label_class) end end end |
#radio_buttons_collection(*args) ⇒ Object
167 168 169 170 |
# File 'lib/bootstrap_form/form_builder.rb', line 167 def (*args) warn "'BootstrapForm#radio_buttons_collection' is deprecated, use 'BootstrapForm#collection_radio_buttons' instead" (*args) end |
#select_with_bootstrap(method, choices, options = {}, html_options = {}) ⇒ Object
69 70 71 72 73 |
# File 'lib/bootstrap_form/form_builder.rb', line 69 def select_with_bootstrap(method, choices, = {}, = {}) form_group_builder(method, , ) do select_without_bootstrap(method, choices, , ) end end |
#time_zone_select_with_bootstrap(method, priority_zones = nil, options = {}, html_options = {}) ⇒ Object
93 94 95 96 97 |
# File 'lib/bootstrap_form/form_builder.rb', line 93 def time_zone_select_with_bootstrap(method, priority_zones = nil, = {}, = {}) form_group_builder(method, , ) do time_zone_select_without_bootstrap(method, priority_zones, , ) end end |