How to use the ember-cp-validations.validator 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 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-changeset-cp-validations / tests / helpers / validated-object.js View on Github external
import EmberObject from '@ember/object';
import { validator, buildValidations } from 'ember-cp-validations';

export const Validations = buildValidations({
  username: {
    description: 'Username',
    validators: [
      validator('presence', true),
      validator('length', {
        min: 5,
        max: 15
      })
    ]
  },
  password: {
    description: 'Password',
    validators: [
      validator('presence', true),
      validator('length', {
        min: 4,
        max: 10
      })
    ]
  }
github offirgolan / ember-cp-validations / tests / dummy / app / models / order.js View on Github external
import DS from 'ember-data';
import { validator, buildValidations } from 'ember-cp-validations';

const Validations = buildValidations({
  source: {
    description: 'Order Source',
    validators: [validator('ds-error'), validator('presence', true)]
  },
  lines: {
    description: 'Order Lines',
    validators: [
      validator('ds-error'),
      validator('has-many'),
      validator('presence', true)
    ]
  }
});

export default DS.Model.extend(Validations, {
  source: DS.attr('string'),
  lines: DS.hasMany('order-line', { async: true })
});
github offirgolan / ember-cp-validations / tests / dummy / app / models / order-line.js View on Github external
import { validator, buildValidations } from 'ember-cp-validations';

const Validations = buildValidations({
  type: {
    description: 'Order Line Type',
    validators: [validator('ds-error'), validator('presence', true)]
  },
  order: {
    description: 'Order',
    validators: [validator('ds-error'), validator('presence', true)]
  },
  selections: {
    description: 'Order Selections',
    validators: [
      validator('ds-error'),
      validator('has-many'),
      validator('presence', true)
    ]
  }
});

export default DS.Model.extend(Validations, {
  order: DS.belongsTo('order', { async: true }),
  selections: DS.hasMany('order-selection', { async: true }),
  type: DS.attr('string')
});
github ilios / frontend / app / components / offering-form.js View on Github external
gte: 0
    })
  ],
  durationMinutes: [
    validator('number', {
      allowString: true,
      integer: true,
      gte: 0,
      lte: 59
    })
  ],
  learnerGroups: {
    dependentKeys: ['model.smallGroupMode'],
    disabled: not('model.smallGroupMode'),
    validators: [
      validator('length', {
        min: 1,
        messageKey: 'general.smallGroupMessage'
      })
    ]
  },

});

export default Component.extend(ValidationErrorDisplay, Validations, {
  currentUser: service(),
  init(){
    this._super(...arguments);
    this.set('recurringDayOptions', [
      {day: '0', t: 'general.sunday'},
      {day: '1', t: 'general.monday'},
      {day: '2', t: 'general.tuesday'},
github CenterForOpenScience / ember-osf-web / app / models / user-setting.ts View on Github external
import { attr, belongsTo } from '@ember-decorators/data';
import { buildValidations, validator } from 'ember-cp-validations';
import { Link } from 'jsonapi-typescript';

import getHref from 'ember-osf-web/utils/get-href';

import OsfModel, { OsfLinks } from './osf-model';
import UserModel from './user';

const Validations = buildValidations({
    twoFactorVerification: [
        validator('presence', true),
        validator('number', {
            allowString: true,
            integer: true,
            positive: true,
        }),
    ],
});
export interface UserSettingsLinks extends OsfLinks {
    export: Link;
}

export default class UserSettingModel extends OsfModel.extend(Validations) {
    @attr() links!: UserSettingsLinks;
    @attr('boolean') twoFactorEnabled!: boolean;
    @attr('boolean') twoFactorConfirmed!: boolean;
    @attr('boolean') subscribeOsfHelpEmail!: boolean;
github adiwg / mdEditor / app / pods / components / object / md-time-period / component.js View on Github external
'intervalAmount': [
    validator('presence', {
      presence: true,
      //disabled: computed.notEmpty('model.endDateTime'),
      ignoreBlank: true
    })
  ],
  'startDateTime': [
    validator('presence', {
      presence: true,
      disabled: notEmpty('model.endDateTime'),
      ignoreBlank: true
    })
  ],
  'endDateTime': [
    validator('date', {
      onOrAfter: alias('model.startDateTime'),
      isWarning: true
    }),
    validator('presence', {
      presence: true,
      disabled: notEmpty('model.startDateTime'),
      ignoreBlank: true
    })
  ]
});

export default Component.extend(Validations, {
  didReceiveAttrs() {
    this._super(...arguments);

    let model = get(this, 'model');
github adiwg / mdEditor / app / pods / components / object / md-keyword-citation / component.js View on Github external
import { alias } from '@ember/object/computed';

import { isArray } from '@ember/array';
import { computed } from '@ember/object';
import Component from '@ember/component';
import {
  regex
} from '../md-online-resource/component';
import {
  validator,
  buildValidations
} from 'ember-cp-validations';

const Validations = buildValidations({
  'onlineResource': [
    validator('format', {
      regex: regex,
      isWarning: true,
      message: 'This field should be a valid, resolvable uri.',
      dependentKeys: ['onlineResource', 'model.thesaurus.onlineResource.0.uri']
    })
  ],
  title: validator('presence', {
    presence: true,
    ignoreBlank: true
  })
});

export default Component.extend(Validations, {
  disabled: computed('model.thesaurus.identifier.0.identifier',
    function() {
      return this.get('model.thesaurus.identifier.0.identifier') !==
github NREL / api-umbrella / src / api-umbrella / admin-ui / app / models / api.js View on Github external
name: validator('presence', true),
  frontendHost: [
    validator('presence', true),
    validator('format', {
      regex: CommonValidations.host_format_with_wildcard,
      message: I18n.t('errors.messages.invalid_host_format'),
    }),
  ],
  backendHost: [
    validator('presence', {
      presence: true,
      disabled: computed('model.frontendHost', function() {
        return (this.model.frontendHost && this.model.frontendHost[0] === '*');
      }),
    }),
    validator('format', {
      regex: CommonValidations.host_format_with_wildcard,
      message: I18n.t('errors.messages.invalid_host_format'),
      disabled: computed.not('model.backendHost'),
    }),
  ],
});

export default Model.extend(Validations, {
  name: attr(),
  sortOrder: attr('number'),
  backendProtocol: attr('string', { defaultValue: 'http' }),
  frontendHost: attr(),
  backendHost: attr(),
  balanceAlgorithm: attr('string', { defaultValue: 'least_conn' }),
  createdAt: attr(),
  updatedAt: attr(),