2020-01-18 10:13:50 +01:00
|
|
|
import classic from 'ember-classic-decorator';
|
2015-11-18 17:49:01 +01:00
|
|
|
import BaseValidator from 'ember-cp-validations/validators/base';
|
|
|
|
|
2020-01-18 10:13:50 +01:00
|
|
|
@classic
|
|
|
|
export default class ValidCollectionValidator extends BaseValidator {
|
2015-11-19 21:51:49 +01:00
|
|
|
validate(value, options) {
|
|
|
|
if (options.active === false) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2016-01-28 23:48:14 +01:00
|
|
|
const valid = value.every((element) => {
|
2015-11-18 17:49:01 +01:00
|
|
|
return element.get('validations.isValid');
|
|
|
|
});
|
2015-11-19 21:16:32 +01:00
|
|
|
|
|
|
|
if (valid) {
|
|
|
|
return true;
|
2016-01-28 23:48:14 +01:00
|
|
|
} else {
|
2015-11-22 19:11:32 +01:00
|
|
|
return this.createErrorMessage('validCollection', options, value);
|
2015-11-19 21:16:32 +01:00
|
|
|
}
|
2015-11-18 17:49:01 +01:00
|
|
|
}
|
2020-01-18 10:13:50 +01:00
|
|
|
}
|