Module: BootstrapForm::CheckBoxPatch
- Defined in:
- lib/bootstrap_form/check_box_patch.rb
Instance Method Summary collapse
-
#check_box(name, options = {}, checked_value = "1", unchecked_value = "0", &block) ⇒ Object
TODO: check upstream - it is on master on 29-1-2018 - only required is not there.
Instance Method Details
#check_box(name, options = {}, checked_value = "1", unchecked_value = "0", &block) ⇒ Object
TODO: check upstream - it is on master on 29-1-2018 - only required is not there
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/bootstrap_form/check_box_patch.rb', line 5 def check_box(name, = {}, checked_value = "1", unchecked_value = "0", &block) = .symbolize_keys! = .except(:label, :label_class, :wrapper_class, :help, :inline) label_classes = [[:label_class], 'form-check-label'] unless .delete(:skip_required) label_classes << "required" if required_attribute?(object, name) end [:label_class] = label_classes.compact.join(' ') [:class] = ['form-check-input', [:class]].compact.join(' ') 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's `for` attribute needs to match checkbox tag's id, # IE sanitized value, IE # https://github.com/rails/rails/blob/c57e7239a8b82957bcb07534cb7c1a3dcef71864/actionview/lib/action_view/helpers/tags/base.rb#L116-L118 if [:multiple] label_name = "#{name}_#{checked_value.to_s.gsub(/\s/, "_").gsub(/[^-\w]/, "").downcase}" end 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 wrapper_class = ['form-check', [:wrapper_class]] wrapper_class << error_class if has_error?(name) wrapper_class = wrapper_class.compact.join(' ') content_tag(:div, class: "#{wrapper_class}#{disabled_class}") do label(label_name, html, class: label_class).concat(generate_help(name, [:help])) end end end |