Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dependent field validation capability #346

Open
ctwoolsey opened this issue Jun 24, 2022 · 0 comments
Open

Dependent field validation capability #346

ctwoolsey opened this issue Jun 24, 2022 · 0 comments

Comments

@ctwoolsey
Copy link

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

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;
  }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant