adopted-ember-addons / adopted-ember-addons/ember-cp-validations
Dependency Related Challenge
- 主要语言
- JavaScript
- 星标
- 439
- 派生
- 172
- PR 合并指标
- 30 天内没有已合并 PR
描述
### Environment
Hello Guys, I am very new in Ember application. So please suggest me.
I am facing a problem while doing validation.
I am having a form where there are multiple fields.
There are two fields which are dependent on each other are companyname and abnnumber.
Scenario:
Company Name is optional.
if the user enters any value in company name then only abnnumber should validate.
If the user doesn't enter any value in the companyname field then abnnumber should not validate and move to another field to validate.
In the starting both are blank.
I have tried to overcome this problem in this way, please suggest me the solution.
const Validations = buildValidations({
company: {
description: "Company",
validators: [
validator('length', { max: 50 }),
validator('format', {
regex: /^[a-zA-Z0-9,.@&#' \-+]*$/,
message: 'Invalid characters'
}),
]
},
abn:
[
// I have created a custom validation to validate abn no conditionally
validator('abn-number'),
],
});
import BaseValidator from 'ember-cp-validations/validators/base';
import moment from 'moment';
const AbnNumber = BaseValidator.extend({
validate(value, options, model) {
if(model.company != '' && model.company != null){
if(model.abn == '' || model.abn == null){
return "Please provide ABN";
}else{
return true;
}
}else{
return true;
}
}
});
AbnNumber.reopenClass({
getDependentsFor() {
return ['abn','company'];
}
});
export default AbnNumber;
if you guys let me know the solution, it will great and very big help to me.
If there is any other solution apart from this, please let me know. Also if there is no need of custom validation which i have created please let me know the substitute for this.
Thanks in advance.
- Ember CLI Version: 2.6.3
- Ember CP Validations Version: 3.1.2
### Steps to Reproduce
贡献指南
评估
这个 Issue 还没有评估数据。