module Symphonia class FormBuilder < ::BootstrapForm::FormBuilder def error_messages if object.respond_to?(:errors) && object.errors.any? list = content_tag(:p, I18n.t('activerecord.errors.template.body')).html_safe list += content_tag(:ul) do object.errors.full_messages.collect do |error| content_tag(:li, error) end.join.html_safe end content_tag(:div, list, class: 'error_explanation') end end def calendar_field(name, options = {}) options[:data] ||= {} #{'date-clear-btn': true, 'date-format': 'yyyy-mm-dd'} options[:data][:'date-clear-btn'] ||= true # options[:data][:'date-format'] ||= 'yyyy-mm-dd' text_field(name, options.merge({ class: 'form-control datepicker', append: @template.fa_icon('calendar') })) end # def form_group_builder(method, options, html_options = nil) # options.symbolize_keys! # html_options.symbolize_keys! if html_options # # # Add control_class; allow it to be overridden by :control_class option # css_options = html_options || options # control_classes = css_options.delete(:control_class) { control_class } # css_options[:class] = [control_classes, css_options[:class]].compact.join(" ") # css_options[:class] << " is-invalid" if has_error?(method) # # options = convert_form_tag_options(method, options) if acts_like_form_tag # # wrapper_class = css_options.delete(:wrapper_class) # wrapper_options = css_options.delete(:wrapper) # help = options.delete(:help) # icon = options.delete(:icon) # label_col = options.delete(:label_col) # control_col = options.delete(:control_col) # layout = get_group_layout(options.delete(:layout)) # form_group_options = { # id: options[:id], # help: help, # icon: icon, # label_col: label_col, # control_col: control_col, # layout: layout, # class: wrapper_class # } # # if wrapper_options.is_a?(Hash) # form_group_options.merge!(wrapper_options) # end # # unless options.delete(:skip_label) # if options[:label].is_a?(Hash) # label_text = options[:label].delete(:text) # label_class = options[:label].delete(:class) # options.delete(:label) # end # label_class ||= options.delete(:label_class) # label_class = hide_class if options.delete(:hide_label) # # if options[:label].is_a?(String) # label_text ||= options.delete(:label) # end # # form_group_options.merge!(label: { # text: label_text, # class: label_class, # skip_required: options.delete(:skip_required), # required: options.delete(:required) # }) # end # # form_group(method, form_group_options) do # yield # end # end def label_text(name, options) name = name.to_s.remove(/_id$/) if label_errors && error?(name) (options[:text] || object.class.human_attribute_name(name)).to_s.concat(" #{get_error_messages(name)}") else options[:text] end end # def generate_label(id, name, options, custom_label_col, group_layout) # return if options.blank? # # id is the caller's options[:id] at the only place this method is called. # # The options argument is a small subset of the options that might have # # been passed to generate_label's caller, and definitely doesn't include # # :id. # options[:for] = id if acts_like_form_tag # classes = [options[:class]] # # if layout_horizontal?(group_layout) # classes << "col-form-label" # classes << (custom_label_col || label_col) # elsif layout_inline?(group_layout) # classes << "mr-sm-2" # end # # xname = name.to_s.remove(/_id$/) # # case options.delete(:required) # when true # classes << "required" # when nil, :default # classes << "required" if required_attribute?(object, name) # end # # options[:class] = classes.compact.join(" ").strip # options.delete(:class) if options[:class].empty? # # if label_errors && has_error?(name) # error_messages = get_error_messages(name) # label_text = (options[:text] || object.class.human_attribute_name(xname)).to_s.concat(" #{error_messages}") # options[:class] = [options[:class], "text-danger"].compact.join(" ") # label(name, label_text, options.except(:text)) # else # label(name, options[:text], options.except(:text)) # end # end def error_class 'is-invalid' end end end