Module: BootstrapForm::Helpers::Bootstrap
- Includes:
- ActionView::Helpers::OutputSafetyHelper
- Included in:
- FormBuilder
- Defined in:
- lib/bootstrap_form/helpers/bootstrap.rb
Instance Method Summary collapse
- #alert_message(title, options = {}) ⇒ Object
- #custom_control(*args) ⇒ Object
- #error_summary ⇒ Object
- #errors_on(name, options = {}) ⇒ Object
- #input_group_content(content) ⇒ Object
- #input_with_error(name, id) ⇒ Object
- #prepend_and_append_input(name, options) ⇒ Object
- #static_class ⇒ Object
- #static_control(*args) ⇒ Object
Instance Method Details
#alert_message(title, options = {}) ⇒ Object
8 9 10 11 12 13 14 15 16 17 18 19 |
# File 'lib/bootstrap_form/helpers/bootstrap.rb', line 8 def (title, ={}) css = [:class] || "alert alert-danger" return unless object.respond_to?(:errors) && object.errors..any? tag.div class: css do if [:error_summary] == false title else tag.p(title) + error_summary end end end |
#custom_control(*args) ⇒ Object
64 65 66 67 68 69 |
# File 'lib/bootstrap_form/helpers/bootstrap.rb', line 64 def custom_control(*args, &) = args. name = args.first form_group_builder(name, , &) end |
#error_summary ⇒ Object
21 22 23 24 25 26 27 28 29 |
# File 'lib/bootstrap_form/helpers/bootstrap.rb', line 21 def error_summary return unless object.errors.any? tag.ul(class: "rails-bootstrap-forms-error-summary") do object.errors..reduce(ActiveSupport::SafeBuffer.new) do |acc, error| acc << tag.li(error) end end end |
#errors_on(name, options = {}) ⇒ Object
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/bootstrap_form/helpers/bootstrap.rb', line 31 def errors_on(name, ={}) return unless error?(name) hide_attribute_name = [:hide_attribute_name] || false custom_class = [:custom_class] || false tag.div( class: custom_class || "invalid-feedback", id: aria_feedback_id(id: [:id], name:) ) do errors = if hide_attribute_name object.errors[name] else object.errors.(name) end safe_join(errors, ", ") end end |
#input_group_content(content) ⇒ Object
89 90 91 92 93 |
# File 'lib/bootstrap_form/helpers/bootstrap.rb', line 89 def input_group_content(content) return content if content.include?("btn") tag.span(content, class: "input-group-text") end |
#input_with_error(name, id) ⇒ Object
84 85 86 87 |
# File 'lib/bootstrap_form/helpers/bootstrap.rb', line 84 def input_with_error(name, id, &) input = capture(&) input << generate_error(name, id) end |
#prepend_and_append_input(name, options) ⇒ Object
71 72 73 74 75 76 77 78 79 80 81 82 |
# File 'lib/bootstrap_form/helpers/bootstrap.rb', line 71 def prepend_and_append_input(name, , &) id = [:id] = .extract!(:prepend, :append, :input_group_class).compact input = capture(&) || ActiveSupport::SafeBuffer.new input = attach_input(, :prepend) + input + attach_input(, :append) input << generate_error(name, id) .present? && input = tag.div(input, class: ["input-group", [:input_group_class]].compact) input end |
#static_class ⇒ Object
95 96 97 |
# File 'lib/bootstrap_form/helpers/bootstrap.rb', line 95 def static_class "form-control-plaintext" end |
#static_control(*args) ⇒ Object
50 51 52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/bootstrap_form/helpers/bootstrap.rb', line 50 def static_control(*args) = args. name = args.first = .merge( readonly: true, control_class: [[:control_class], static_class].compact ) [:value] = object.send(name) unless .key?(:value) text_field_with_bootstrap(name, ) end |