Class: Binco::BootstrapFormBuilder
- Inherits:
-
ActionView::Helpers::FormBuilder
- Object
- ActionView::Helpers::FormBuilder
- Binco::BootstrapFormBuilder
- Defined in:
- app/helpers/binco/bootstrap_form_builder.rb
Constant Summary collapse
- CHECK_BOX_GROUP_CLASS =
'form-check'
- CHECK_BOX_LABEL_CLASS =
'form-check-label'
- FORM_ELEMENT_CLASS =
'form-control'
- CHECK_BOX_INPUT_CLASS =
'form-check-input'
- ERROR_PROC =
Proc.new do |html_tag, instance| if instance.class.to_s != 'ActionView::Helpers::Tags::Label' = instance..collect{ |error| "<div class=\"invalid-feedback\">#{error}</div>" }.join "#{html_tag.gsub(/class="/, 'class="is-invalid ')} #{}".html_safe else html_tag end end
Instance Method Summary collapse
- #addon(icon, options = {}) ⇒ Object
- #check_box(method, options = {}, checked_value = "1", unchecked_value = "0") ⇒ Object
- #check_box_original ⇒ Object
- #check_label(method, options = {}, &block) ⇒ Object (also: #check_box_label)
- #collection_check_boxes(method, collection, value_method, text_method, options = {}, html_options = {}, &block) ⇒ Object
-
#collection_check_boxes2(method, collection, value_method, text_method, options = {}, html_options = {}) ⇒ Object
Since select2 support multiple choices (checkboxes).
- #collection_select(method, collection, value_method, text_method, options = {}, html_options = {}) ⇒ Object
- #collection_select2(method, collection, value_method, text_method, options = {}, html_options = {}, &block) ⇒ Object
- #collection_select_original ⇒ Object
- #custom_check_box(method, options = {}, checked_value = "1", unchecked_value = "0") ⇒ Object
- #datepicker(method, options = {}) ⇒ Object
- #email_field(name, options = {}) ⇒ Object
- #file_field(method, options = {}) ⇒ Object
- #form_check(options = {}, &block) ⇒ Object (also: #check_box_group)
- #form_group(options = {}, &block) ⇒ Object
-
#initialize(object_name, object, template, options) ⇒ BootstrapFormBuilder
constructor
A new instance of BootstrapFormBuilder.
- #input_group(options = {}, &block) ⇒ Object
- #input_group_append(content, options = {}) ⇒ Object
- #input_group_prepend(content, options = {}) ⇒ Object
- #number_field(name, options = {}) ⇒ Object
- #password_field(name, options = {}) ⇒ Object
- #radio_button(method, tag_value, options = {}) ⇒ Object
- #radio_group(options = {}, &block) ⇒ Object
- #select(method, choices = nil, options = {}, html_options = {}, &block) ⇒ Object
- #select2(method, choices = nil, options = {}, html_options = {}, &block) ⇒ Object
- #select_original ⇒ Object
- #submit(value = nil, options = {}) ⇒ Object
- #submit_original ⇒ Object
- #telephone_field(name, options = {}) ⇒ Object (also: #phone_field)
- #text_area(method, options = {}) ⇒ Object
- #text_field(name, options = {}) ⇒ Object
Constructor Details
#initialize(object_name, object, template, options) ⇒ BootstrapFormBuilder
Returns a new instance of BootstrapFormBuilder.
23 24 25 26 27 |
# File 'app/helpers/binco/bootstrap_form_builder.rb', line 23 def initialize(object_name, object, template, ) ActionView::Base::field_error_proc = ERROR_PROC super(object_name, object, template, ) end |
Instance Method Details
#addon(icon, options = {}) ⇒ Object
163 164 165 |
# File 'app/helpers/binco/bootstrap_form_builder.rb', line 163 def addon(icon, = {}) input_group_append(icon, ) end |
#check_box(method, options = {}, checked_value = "1", unchecked_value = "0") ⇒ Object
110 111 112 113 |
# File 'app/helpers/binco/bootstrap_form_builder.rb', line 110 def check_box(method, = {}, checked_value = "1", unchecked_value = "0") = (CHECK_BOX_INPUT_CLASS, ) super method, , checked_value, unchecked_value end |
#check_box_original ⇒ Object
4 |
# File 'app/helpers/binco/bootstrap_form_builder.rb', line 4 alias_method :check_box_original, :check_box |
#check_label(method, options = {}, &block) ⇒ Object Also known as: check_box_label
152 153 154 155 |
# File 'app/helpers/binco/bootstrap_form_builder.rb', line 152 def check_label(method, = {}, &block) = (CHECK_BOX_LABEL_CLASS, ) @template.label(@object_name, method, nil, (), &block) end |
#collection_check_boxes(method, collection, value_method, text_method, options = {}, html_options = {}, &block) ⇒ Object
50 51 52 53 54 55 56 57 58 59 60 61 62 |
# File 'app/helpers/binco/bootstrap_form_builder.rb', line 50 def collection_check_boxes(method, collection, value_method, text_method, = {}, = {}, &block) if block_given? super(method, collection, value_method, text_method, , , &block) else super method, collection, value_method, text_method, , do |b| group_tag class: CHECK_BOX_GROUP_CLASS do b.label class: CHECK_BOX_LABEL_CLASS do b.check_box(class: CHECK_BOX_INPUT_CLASS) + " " + b.text end end end end end |
#collection_check_boxes2(method, collection, value_method, text_method, options = {}, html_options = {}) ⇒ Object
Since select2 support multiple choices (checkboxes)
65 66 67 68 69 |
# File 'app/helpers/binco/bootstrap_form_builder.rb', line 65 def collection_check_boxes2(method, collection, value_method, text_method, = {}, = {}) ||= {} [:multiple] = 'multiple' collection_select2 method, collection, value_method, text_method, , end |
#collection_select(method, collection, value_method, text_method, options = {}, html_options = {}) ⇒ Object
71 72 73 74 |
# File 'app/helpers/binco/bootstrap_form_builder.rb', line 71 def collection_select(method, collection, value_method, text_method, = {}, = {}) = ('custom-select', ) super method, collection, value_method, text_method, , end |
#collection_select2(method, collection, value_method, text_method, options = {}, html_options = {}, &block) ⇒ Object
76 77 78 79 |
# File 'app/helpers/binco/bootstrap_form_builder.rb', line 76 def collection_select2(method, collection, value_method, text_method, = {}, = {}, &block) = ('select2-rails', ) collection_select_original(method, collection, value_method, text_method, , ) end |
#collection_select_original ⇒ Object
3 |
# File 'app/helpers/binco/bootstrap_form_builder.rb', line 3 alias_method :collection_select_original, :collection_select |
#custom_check_box(method, options = {}, checked_value = "1", unchecked_value = "0") ⇒ Object
115 116 117 118 119 120 121 122 123 |
# File 'app/helpers/binco/bootstrap_form_builder.rb', line 115 def custom_check_box(method, = {}, checked_value = "1", unchecked_value = "0") = ('custom-control-input', ) base_proc = ActionView::Base::field_error_proc ActionView::Base::field_error_proc = Proc.new { |html_tag, instance| html_tag } html = check_box_original(method, , checked_value, unchecked_value) ActionView::Base::field_error_proc = base_proc return html end |
#datepicker(method, options = {}) ⇒ Object
96 97 98 99 |
# File 'app/helpers/binco/bootstrap_form_builder.rb', line 96 def datepicker(method, = {}) = ({ provide: 'datepicker' }, ) text_field(method, ) end |
#email_field(name, options = {}) ⇒ Object
81 82 83 84 |
# File 'app/helpers/binco/bootstrap_form_builder.rb', line 81 def email_field(name, = {}) = (FORM_ELEMENT_CLASS, ) super name, end |
#file_field(method, options = {}) ⇒ Object
125 126 127 128 |
# File 'app/helpers/binco/bootstrap_form_builder.rb', line 125 def file_field(method, = {}) = ('form-control-file', ) super method, end |
#form_check(options = {}, &block) ⇒ Object Also known as: check_box_group
146 147 148 149 |
# File 'app/helpers/binco/bootstrap_form_builder.rb', line 146 def form_check( = {}, &block) = (CHECK_BOX_GROUP_CLASS, ) group_tag , &block end |
#form_group(options = {}, &block) ⇒ Object
136 137 138 139 |
# File 'app/helpers/binco/bootstrap_form_builder.rb', line 136 def form_group( = {}, &block) = ('form-group', ) group_tag , &block end |
#input_group(options = {}, &block) ⇒ Object
158 159 160 161 |
# File 'app/helpers/binco/bootstrap_form_builder.rb', line 158 def input_group( = {}, &block) = ('input-group', ) group_tag , &block end |
#input_group_append(content, options = {}) ⇒ Object
172 173 174 175 |
# File 'app/helpers/binco/bootstrap_form_builder.rb', line 172 def input_group_append(content, = {}) = ('input-group-append', ) @template.content_tag(:div, @template.content_tag(:span, content, { class: 'input-group-text' }), ) end |
#input_group_prepend(content, options = {}) ⇒ Object
167 168 169 170 |
# File 'app/helpers/binco/bootstrap_form_builder.rb', line 167 def input_group_prepend(content, = {}) = ('input-group-prepend', ) @template.content_tag(:div, @template.content_tag(:span, content, { class: 'input-group-text' }), ) end |
#number_field(name, options = {}) ⇒ Object
86 87 88 89 |
# File 'app/helpers/binco/bootstrap_form_builder.rb', line 86 def number_field(name, = {}) = (FORM_ELEMENT_CLASS, ) super name, end |
#password_field(name, options = {}) ⇒ Object
91 92 93 94 |
# File 'app/helpers/binco/bootstrap_form_builder.rb', line 91 def password_field(name, = {}) = (FORM_ELEMENT_CLASS, ) super name, end |
#radio_button(method, tag_value, options = {}) ⇒ Object
106 107 108 |
# File 'app/helpers/binco/bootstrap_form_builder.rb', line 106 def (method, tag_value, = {}) super method, tag_value, end |
#radio_group(options = {}, &block) ⇒ Object
141 142 143 144 |
# File 'app/helpers/binco/bootstrap_form_builder.rb', line 141 def radio_group( = {}, &block) = ('radio', ) group_tag , &block end |
#select(method, choices = nil, options = {}, html_options = {}, &block) ⇒ Object
40 41 42 43 |
# File 'app/helpers/binco/bootstrap_form_builder.rb', line 40 def select(method, choices = nil, = {}, = {}, &block) = ('custom-select', ) super method, choices, , , &block end |
#select2(method, choices = nil, options = {}, html_options = {}, &block) ⇒ Object
45 46 47 48 |
# File 'app/helpers/binco/bootstrap_form_builder.rb', line 45 def select2(method, choices = nil, = {}, = {}, &block) = ('select2-rails', ) select_original method, choices, , , &block end |
#select_original ⇒ Object
5 |
# File 'app/helpers/binco/bootstrap_form_builder.rb', line 5 alias_method :select_original, :select |
#submit(value = nil, options = {}) ⇒ Object
130 131 132 133 134 |
# File 'app/helpers/binco/bootstrap_form_builder.rb', line 130 def submit(value = nil, = {}) = ('btn btn-success', ) ({ disable_with: 'Enviando' }, ) super value, end |
#submit_original ⇒ Object
6 |
# File 'app/helpers/binco/bootstrap_form_builder.rb', line 6 alias_method :submit_original, :submit |
#telephone_field(name, options = {}) ⇒ Object Also known as: phone_field
34 35 36 37 |
# File 'app/helpers/binco/bootstrap_form_builder.rb', line 34 def telephone_field(name, = {}) = (FORM_ELEMENT_CLASS, ) super name, end |
#text_area(method, options = {}) ⇒ Object
101 102 103 104 |
# File 'app/helpers/binco/bootstrap_form_builder.rb', line 101 def text_area(method, = {}) = (FORM_ELEMENT_CLASS, ) super(method, ) end |
#text_field(name, options = {}) ⇒ Object
29 30 31 32 |
# File 'app/helpers/binco/bootstrap_form_builder.rb', line 29 def text_field(name, = {}) = (FORM_ELEMENT_CLASS, ) super name, end |