module ErrorItemsHelper
  def error_items(error_messages, field)
    if error_messages.key?(field)
      error_messages[field].map { |message| "#{field.to_s.titleize} #{message}".capitalize }.join("\n")
    end
  end

  def errors_for(object, attribute)
    object.errors.errors.filter_map do |error|
      if error.attribute == attribute
        {
          text: error.options[:message],
        }
      end
    end
  end
end

module ErrorItemsHelper
  def error_items(error_messages, field)
    if error_messages.key?(field)
      error_messages[field].map { |message| "#{field.to_s.titleize} #{message}".capitalize }.join("\n")
    end
  end

  def errors_for(object, attribute)
    return nil if object.errors.blank?

    object.errors.errors.filter_map do |error|
      if error.attribute == attribute
        {
          text: error.options[:message],
        }
      end
    end
  end
end

Update error items helper to handle checkbox component
Update error items helper to handle checkbox component

The error handling for this component is built slightly differently
to the other components. Resultantly, an empty array is rendered
as an error message for the checkbox component. This is due to there
not being a presence check within the component before errors are
passed back.

This is easily mitigated on our end by ensuring that objects passed into
the errors_for method return nil when errors are not present.
