Module: CoreFormCheckboxHelper
- Defined in:
- app/helpers/core_form_checkbox_helper.rb
Instance Method Summary collapse
- #form_checkbox(model, field, options = {}) ⇒ Object abstract
- #form_checkbox_label_tag(model, field, value, options = {}) ⇒ Object
Instance Method Details
#form_checkbox(model, field, options = {}) ⇒ Object
This method is abstract.
Render a text field
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'app/helpers/core_form_checkbox_helper.rb', line 6 def form_checkbox(model, field, = {}) classes = [:classes] || [] value = model.send(field) [:disabled] ||= false properties = { class: 'form-check-input', id: form_field_id(model, field, ), name: form_field_name(model, field, ), type: :checkbox, disabled: [:disabled] } properties[:checked] = true if model.send(field) checkbox_tag = tag(:input, properties) content_tag(:div, class: (%w[mb-3 align-items-center d-flex] + classes).join(' ')) do concat(content_tag(:label, class: 'form-check form-switch align-middle') do concat(checkbox_tag) concat(form_checkbox_label_tag(model, field, value, input_classes: classes)) end) end end |
#form_checkbox_label_tag(model, field, value, options = {}) ⇒ Object
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'app/helpers/core_form_checkbox_helper.rb', line 27 def form_checkbox_label_tag(model, field, value, = {}) # dont do a label if we are in default browser mode return if [:input_classes].present? && [:input_classes].include?('browser-default') # or if we have a prompt with now value place_holder = form_place_holder_text(model, field) return if place_holder.blank? && value.blank? && [:prompt].present? error = model.errors[field] label = input_label(model, field) classes = value.nil? && place_holder.blank? ? '' : 'active' classes += error.present? ? ' invalid red-text' : ' valid' [:class] = classes ['data-error'] = error.join(', ') if error.present? content_tag(:span, ) { label} end |