When validate
is called on a Record
it recursively calls validate
on each field. However, if a field is a list like BsonRecordListField
then it does not have any validations
registered by default which leads to elements of a list not being validated when validate
is called from parent scope.
It's not difficult to override validations
on a list field to map over all elements to get truly complete validation. I wonder though if that behaviour is by design or is it a bug? To me it seems more natural to validate all fields and their elements (list elems in this case).
Override could look like this for example:
object listOfThings extends BsonRecordListField(this, SomeBsonMetaRecord) {
override def validations = ((elems: ValueType) => elems.map(_.validate).flatten) :: super.validations
}
The problem is that you have to remember to do it for all list based fields.
I'm just guessing that implementation is left to the user because of the flatten
there, i.e. there could be multiple errors from multiple elements but with the same FieldIdentifier
- not clear which element in the list caused an error - need to come up with a custom way to differentiate errors by element position or otherwise.
Got reply from Tim Nelson who created a ticket to address this: https://github.com/lift/framework/issues/1587, milestone 3.0-M2. This might still be discussed but looks like it will probably get fixed.
Discussion on lift google group: https://groups.google.com/forum/#!msg/liftweb/gh2syNeGWyw/OC3y2TLWfAkJ.