module Storefront class Form module Errors def errors_for(key, options = {}) value = options[:error_attributes].delete(:value) template.capture_haml do if value.present? template.haml_tag :output, options[:error_attributes] do template.haml_concat value.html_safe end else template.haml_tag :output, options[:error_attributes] end end end def errors_on?(attribute, options = {}) end def required?(attribute) attribute_sym = attribute.to_s.sub(/_id$/, '').to_sym if @object && @object.class.respond_to?(:reflect_on_validations_for) @object.class.reflect_on_validations_for(attribute_sym).any? do |validation| (validation.macro == :validates_presence_of || validation.macro == :validates_inclusion_of) && validation.name == attribute_sym && (validation.options.present? ? options_require_validation?(validation.options) : true) end else if @object && @object.class.respond_to?(:validators_on) !@object.class.validators_on(attribute_sym).find{|validator| (validator.kind == :presence || validator.kind == :inclusion) && (validator.options.present? ? options_require_validation?(validator.options) : true)}.nil? else true end end end def options_require_validation?(options) #nodoc allow_blank = options[:allow_blank] return !allow_blank unless allow_blank.nil? if_condition = !options[:if].nil? condition = if_condition ? options[:if] : options[:unless] condition = if condition.respond_to?(:call) condition.call(@object) elsif condition.is_a?(::Symbol) && @object.respond_to?(condition) @object.send(condition) else condition end if_condition ? !!condition : !condition end end end end