Skip to content

Instantly share code, notes, and snippets.

@allthesignals
Last active May 10, 2020 19:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save allthesignals/39db0a45597bf25291e4dea720a8b32a to your computer and use it in GitHub Desktop.
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
Copy link
Author

allthesignals commented May 10, 2020

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