forked from adiwg/mdEditor
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy patharray-valid.js
42 lines (39 loc) · 1.16 KB
/
array-valid.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
import { get } from '@ember/object';
import BaseValidator from 'ember-cp-validations/validators/base';
const ArrayValid = BaseValidator.extend({
/**
* Validation that checks validity of all array members
*
* @module mdeditor
* @submodule validator
* @class array-valid
* @extends BaseValidator
* @example
* validator('array-valid')
*/
validate(value /*, options, model, attribute*/ ) {
let check = value.some((itm) => {
return get(itm, 'validations.isInvalid');
});
return check ? 'At least one item is invalid.' : true;
}
});
ArrayValid.reopenClass({
/**
* Define attribute specific dependent keys for your validator
*
* [
* `model.array.@each.${attribute}` --> Dependent is created on the model's context
* `${attribute}.isValid` --> Dependent is created on the `model.validations.attrs` context
* ]
*
* @property getDependentsFor
* @param {String} attribute The attribute being evaluated
* @param {Unknown} options Options passed into your validator
* @return {Array}
*/
getDependentsFor(attribute /*, options */ ) {
return [`model.${attribute}.@each`];
}
});
export default ArrayValid;