diff --git a/lib/class/field.js b/lib/class/field.js index 25a7339e..31c9ee43 100644 --- a/lib/class/field.js +++ b/lib/class/field.js @@ -663,7 +663,41 @@ Field.setMethod(function getRecordValue(record, path_to_value_hint) { }); /** - * Cast the given value to this field's type + * Cast the value (could be in a container) + * + * @author Jelle De Loecker + * @since 1.4.0 + * @version 1.4.0 + * + * @param {*} value + * @param {boolean} to_datasource Is this meant for the datasource? + * + * @return {*} + */ +Field.setMethod(function castContainedValues(value, to_datasource) { + + if (this.is_translatable && value && this.is_translatable) { + let prefix; + + for (prefix in value) { + value[prefix] = this.cast(value[prefix], to_datasource); + } + } else if (this.is_array && value) { + let i; + + for (i = 0; i < value.length; i++) { + value[i] = this.cast(value[i], to_datasource); + } + } else { + value = this.cast(value, to_datasource); + } + + return value; +}); + +/** + * Cast the given value to this field's type. + * Containers should not be passed (like the array or translation object container) * * @author Jelle De Loecker * @since 0.2.0