Skip to content

Instantly share code, notes, and snippets.

@allthesignals
Last active May 10, 2020 19:13
Show Gist options
  • Select an option

  • Save allthesignals/39db0a45597bf25291e4dea720a8b32a to your computer and use it in GitHub Desktop.

Select an option

Save allthesignals/39db0a45597bf25291e4dea720a8b32a to your computer and use it in GitHub Desktop.
import {
validatePresence,
} from 'ember-changeset-validations/validators';
export default function validatePresenceIf(options) {
const { withValue, on } = options;
return (...args) => {
const [,,, changes, content] = args;
const hasMatchingWith = (changes[on] || content[on]) === withValue;
if (hasMatchingWith) {
return validatePresence(options)(...args);
}
return true;
};
}
@allthesignals

allthesignals commented May 10, 2020

Copy link
Copy Markdown
Author

this could probably be much simpler lol

Updated

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment