How to use ember-cp-validations - 10 common examples

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 / tests / dummy / app / models / user-detail.js View on Github external
// BEGIN-SNIPPET user-detail-model
import { computed } from '@ember/object';

import DS from 'ember-data';
import moment from 'moment';
import { validator, buildValidations } from 'ember-cp-validations';

const { attr } = DS;

const Validations = buildValidations(
  {
    firstName: validator('presence', true),
    lastName: validator('presence', true),
    dob: {
      description: 'Date of  birth',
      validators: [
        validator('presence', true),
        validator('date', {
          before: 'now',
          after: computed(function() {
            return moment()
              .subtract(120, 'years')
              .format('M/D/YYYY');
          }).volatile(),
          format: 'M/D/YYYY',
          message(type, value /*, context */) {
github adiwg / mdEditor / app / models / record.js View on Github external
import uuidV4 from "uuid/v4";
import Model from 'mdeditor/models/base';
import {
  validator,
  buildValidations
} from 'ember-cp-validations';

const Validations = buildValidations({
  'recordId': validator(
    'presence', {
      presence: true,
      ignoreBlank: true,
    }),
  'json.metadata.resourceInfo.resourceType': [
    validator('array-valid'),
    validator('array-required', {
      track: ['type']
    })
  ],
  // 'json.resourceInfo.abstract': validator('presence', {
  //   presence: true,
  //   ignoreBlank: true
  // }),
  'json.metadata.resourceInfo.citation.title': validator('presence', {
    presence: true,
    ignoreBlank: true
  })
  // 'json.metadata.resourceInfo.citation': validator('length', {
  //   min: 1
  // }),
  // 'json.metadata.resourceInfo.status': validator('length', {
  //   min: 1
github CenterForOpenScience / ember-osf-preprints / app / validators / preprint-form-validator.js View on Github external
import { validator, buildValidations } from 'ember-cp-validations';

const Validations = buildValidations({
    title: {
        description: 'Title',
        validators: [
            validator('presence', true),
            validator('length', {
                // minimum length for title?
                max: 300,
            })
        ]
    },
    abstract: {
        description: 'Abstract',
        validators: [
            validator('presence', true),
            validator('length', {
                // minimum length for abstract?
                max: 5000
            })
        ]
    },
    doi: {
github offirgolan / ember-cp-validations / addon / validators / alias.js View on Github external
*
 *  ## Examples
 *
 *  ```javascript
 *  validator('alias', 'attribute')
 *  validator('alias', {
 *    alias: 'attribute',
 *    firstMessageOnly: true
 *  })
 *  ```
 *
 *  @class Alias
 *  @module Validators
 *  @extends Base
 */
const Alias = Base.extend({
  /**
   * Normalized options passed in.
   * ```js
   * validator('alias', 'attribute')
   * // Becomes
   * validator('alias', {
   *   alias: 'attribute'
   * })
   * ```
   *
   * @method buildOptions
   * @param  {Object}     options
   * @param  {Object}     defaultOptions
   * @param  {Object}     globalOptions
   * @return {Object}
   */
github offirgolan / ember-cp-validations / addon / validators / inclusion.js View on Github external
*  validator('inclusion', {
 *    in: ['Admin'] // Input must be equal to 'Admin'
 *  })
 *  validator('inclusion', {
 *    range: [0, Infinity] // Input must be positive number
 *  })
 *  validator('inclusion', {
 *    range: [-Infinity, Infinity] // Input must be a number
 *  })
 *  ```
 *
 *  @class Inclusion
 *  @module Validators
 *  @extends Base
 */
export default EmberValidator.extend({
  _evType: 'inclusion'
});
github offirgolan / ember-cp-validations / addon / validators / presence.js View on Github external
*    presence: true,
 *    message: 'should not be empty'
 *  })
 *
 *  validator('presence', {
 *    presence: true,
 *    ignoreBlank: true,
 *    message: 'should not be empty or consist only of spaces'
 *  })
 *  ```
 *
 *  @class Presence
 *  @module Validators
 *  @extends Base
 */
export default EmberValidator.extend({
  _evType: 'presence',

  /**
   * Normalized options passed in.
   * ```js
   * validator('presence', true)
   * // Becomes
   * validator('presence', {
   *   presence: true
   * })
   * ```
   *
   * @method buildOptions
   * @param  {Object}     options
   * @param  {Object}     defaultOptions
   * @param  {Object}     globalOptions
github offirgolan / ember-cp-validations / addon / validators / number.js View on Github external
*
 *  ```javascript
 *  validator('number') // Simple check if the value is a number
 *  validator('number', {
 *    allowString: true,
 *    integer: true,
 *    gt: 5,
 *    lte: 100
 *  })
 *  ```
 *
 *  @class Number
 *  @module Validators
 *  @extends Base
 */
export default EmberValidator.extend({
  _evType: 'number'
});
github offirgolan / ember-cp-validations / addon / validators / exclusion.js View on Github external
*  ## Examples:
 *
 *  ```javascript
 *  validator('exclusion', {
 *    in: ['Admin', 'Super Admin']
 *  })
 *  validator('exclusion', {
 *    range: [0, 5] // Cannot be between 0 (inclusive) to 5 (inclusive)
 *  })
 *  ```
 *
 *  @class Exclusion
 *  @module Validators
 *  @extends Base
 */
export default EmberValidator.extend({
  _evType: 'exclusion'
});
github offirgolan / ember-cp-validations / addon / validators / collection.js View on Github external
*  ## Examples
 *
 *  ```javascript
 *  validator('collection', true)
 *  validator('collection', false)
 *  validator('collection', {
 *    collection: true,
 *    message: 'must be a collection'
 *  })
 *  ```
 *
 *  @class Collection
 *  @module Validators
 *  @extends Base
 */
const Collection = EmberValidator.extend({
  _evType: 'collection',

  /**
   * Normalized options passed in.
   * ```js
   * validator('collection', true)
   * // Becomes
   * validator('collection', {
   *   collection: true
   * })
   * ```
   *
   * @method buildOptions
   * @param  {Object}     options
   * @param  {Object}     defaultOptions
   * @param  {Object}     globalOptions
github offirgolan / ember-cp-validations / addon / validators / base.js View on Github external
buildOptions(options = {}, defaultOptions = {}, globalOptions = {}) {
    let builtOptions = mergeOptions(options, defaultOptions, globalOptions);

    // Overwrite the validator's value method if it exists in the options and remove it since
    // there is no need for it to be passed around
    this.value = builtOptions.value || this.value;
    delete builtOptions.value;

    return new Options({
      model: get(this, 'model'),
      attribute: get(this, 'attribute'),
      options: builtOptions
    });
  },