adopted-ember-addons / adopted-ember-addons/ember-cp-validations

how to disable "belongs-to" validator?

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

描述

Hi, thank you for your great validation tool - ember-cp-validation. I have a question: how to disable "belongs-to" validator?
I have a model "user", which has "belongs-to" relationship to model "account". In one case I need to validate only "user" and to not validate "account" model, in other case need to validate both.

```
// user model
import Validations from "../cp-validations/models/user"
import DS from "ember-data";

export default DS.Model.extend(Validations, {
lastName: DS.attr("string"),
account: DS.belongsTo("account")
});
```

```
// account model
import Validations from "../cp-validations/models/account"
import DS from "ember-data";

export default DS.Model.extend(Validations, {
login: DS.attr("string")
});
```
The files with validation rules:
```
// "../cp-validations/models/user"
import { validator, buildValidations } from "ember-cp-validations";

export default buildValidations({
lastName: [
validator("presence", { presence: true, message: "* required" }),
validator("length", { max: 50, message: "Max {max} characters" })
],
account: validator("belongs-to")
});
```

```
// "../cp-validations/models/account"
import { validator, buildValidations } from "ember-cp-validations";

export default buildValidations({
login: [
validator("presence", { presence: true, message: "* required" }),
validator("length", { max: 60, message: "Max {max} characters" })
]
});
```

I've tried to use `account: validator("belongs-to", { disabled: true })`, but in this case calling `user.validate().then(....)` the "then" never gets fired.
The 'disabled' attribute works fine for regular validators like "length", "presence", etc. But does not work for "has-many" and "belongs-to" validators

### Environment

- Ember Version: 3.5.0
- Ember CLI Version: 3.5.0
- Ember CP Validations Version: 3.5.3

贡献指南

打开贡献指南

调研方向

Reproduce the case using the validation rules in ../cp-validations/models/user and ../cp-validations/models/account, starting with user.validate(). Compare the behavior of disabled regular validators with the belongs-to and has-many validators. Done means validation resolves when relationship validation is disabled and still validates account when it is enabled.

由索引模型根据 Issue 内容生成。

评估

技术栈
javascript
领域
frontend
Issue 类型
缺陷
难度
4/5
预计耗时
3-5 天
活跃度
停滞
描述清晰度
基本清楚
新手友好度
30/100

把新 issue 发到你的邮箱

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