adopted-ember-addons / adopted-ember-addons/ember-changeset-validations

Dependent field validation capability

未关闭
#346 0 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看
主要语言
JavaScript
星标
215
派生
98
PR 合并指标
30 天内没有已合并 PR

描述

It would be really nice when writing a custom validator to be able to refer to other fields in the validation object. Currently for this level of validation, I have to write code when the field changes to do validation in my component and then use 'changeset.addError' which isn't working as expected. [issue 651 ember-changeset](https://github.com/poteto/ember-changeset/issues/651)

for example:
```
export default {
fieldA: [validatePresence(true)],
fieldB: [validatePresence(true)],
complexField: validateCustom()]
}
```

complexField might validate on the value of 'fieldA' and/or 'fieldB'.
For example:

```
export default function validateCustom({ min, max } = {}) {
return (key, newValue, oldValue, changes, content) => {
if (fieldA === 'A' && newValue === 'Yes it is A') {
return true;
}
if (fieldB=== 'B' && newValue === 'Yes it is B') {
return true;
}
return false;
}
}
```

贡献指南

打开贡献指南

评估

这个 Issue 还没有评估数据。

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。