lib/clevic/extensions.rb in clevic-0.7.0 vs lib/clevic/extensions.rb in clevic-0.8.0

- old
+ new

@@ -130,8 +130,24 @@ @entity ||= model.collection[row] end attr_writer :entity + # return true if validation failed for this indexes field + def has_errors? + # virtual fields don't have metadata + if metadata.nil? + false + else + entity.errors.invalid?( field_name.to_sym ) + end + end + + # return a collection of errors. Unlike AR, this + # will always return an array that will have zero, one + # or many elements. + def errors + [ entity.errors[field_name.to_sym] ].flatten + end end end