How to use the ember-cp-validations/utils/utils.isPromise function in ember-cp-validations

To help you get started, we’ve selected a few ember-cp-validations examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github offirgolan / ember-cp-validations / addon / validators / base.js View on Github external
test(type, ...args) {
    const cache = this.get('_testValidatorCache');
    const unsupportedTypes = ['alias', 'belongs-to', 'dependent', 'has-many'];

    if (unsupportedTypes.includes(type)) {
      throw new Error(
        `[ember-cp-validations] The \`test\` API does not support validators of type: ${type}.`
      );
    }

    cache[type] = cache[type] || lookupValidator(getOwner(this), type).create();
    const result = cache[type].validate(...args);

    if (isPromise(result)) {
      return result.then(r => new TestResult(r), r => new TestResult(r));
    }

    return new TestResult(result);
  }
});
github offirgolan / ember-cp-validations / addon / validators / belongs-to.js View on Github external
validate(value, ...args) {
    if (value) {
      if (isPromise(value)) {
        return value.then(model => this.validate(model, ...args));
      }

      return get(value, 'validations');
    }

    return true;
  }
});
github offirgolan / ember-cp-validations / addon / validators / has-many.js View on Github external
validate(value, ...args) {
    if (value) {
      if (isPromise(value)) {
        return value.then(models => this.validate(models, ...args));
      }

      return value.map(m => get(m, 'validations'));
    }

    return true;
  }
});