How to use the ember-cp-validations.buildValidations 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 / 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 LevelbossMike / ember-statecharts / tests / dummy / app / components / ui-form / component.js View on Github external
formObject: computed('model', function() {
    const owner = getOwner(this);
    const Validations = this.Validations || buildValidations();

    return Buffer.extend(Validations).create(owner.ownerInjection(), {
      content: this.model
    })
  }),
});
github piceaTech / ember-rapid-forms / tests / dummy / app / models / simple_person.js View on Github external
import { computed } from '@ember/object';
import DS from 'ember-data';
const { Model, attr } = DS;
import { validator, buildValidations } from 'ember-cp-validations';
import InputErrors from 'ember-rapid-forms/mixins/input-errors';
import helper from 'ember-rapid-forms/mixins/ember-cp-validations-helper';

const Validations = buildValidations({
  fullName: [
    validator('format', {
      regex: /^[^\s]+(\s[^\s]+)+$/,
      message: 'enter a first and last name'
    }),
    validator('presence', true)
  ],
  password: [
    validator('presence', true),
    validator('length', {
      min: 6
    })
  ],
  comment: validator('presence', true),
  gender: validator('presence', true)
});
github adiwg / mdEditor / app / models / dictionary.js View on Github external
import { Copyable } from 'ember-copy'
import DS from 'ember-data';
import uuidV4 from "uuid/v4";
import { alias } from '@ember/object/computed';
import Model from 'mdeditor/models/base';
import {
  validator,
  buildValidations
} from 'ember-cp-validations';
import EmberObject, { computed } from '@ember/object';

const Validations = buildValidations({
  'json.dataDictionary.citation.title': validator('presence', {
    presence: true,
    ignoreBlank: true
  }),
  'json.dataDictionary.subject': [validator('presence', {
      presence: true,
      ignoreBlank: true
    }),
    validator('array-required', {
      track: []
    })
  ]
});

const JsonDefault = EmberObject.extend({
  init() {
github apache / ambari / contrib / views / wfmanager / src / main / resources / ui / app / components / asset-config.js View on Github external
*    The ASF licenses this file to You under the Apache License, Version 2.0
*    (the "License"); you may not use this file except in compliance with
*    the License.  You may obtain a copy of the License at
*
*        http://www.apache.org/licenses/LICENSE-2.0
*
*    Unless required by applicable law or agreed to in writing, software
*    distributed under the License is distributed on an "AS IS" BASIS,
*    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
*    See the License for the specific language governing permissions and
*    limitations under the License.
*/
import Ember from 'ember';
import { validator, buildValidations } from 'ember-cp-validations';

const Validations = buildValidations({
  'assetModel.name': validator('presence', {
    presence : true
  })
});

export default Ember.Component.extend(Validations, {
  assetManager : Ember.inject.service('asset-manager'),
  initialize: function(){
    this.$('#asset_config_dialog').modal('show');
    this.$('#asset_config_dialog').modal().on('hidden.bs.modal', function() {
      this.sendAction('showAssetConfig', false);
    }.bind(this));
  }.on('didInsertElement'),
  actions: {
    close() {
      this.$('#asset_config_dialog').modal('hide');
github jelhan / croodle / app / controllers / create / settings.js View on Github external
import { inject as service } from '@ember/service';
import { alias } from '@ember/object/computed';
import Controller from '@ember/controller';
import { getOwner } from '@ember/application';
import { isEmpty } from '@ember/utils';
import EmberObject, { observer, computed } from '@ember/object';
import {
  validator, buildValidations
}
from 'ember-cp-validations';
import moment from 'moment';

const Validations = buildValidations({
  anonymousUser: validator('presence', {
    presence: true,
    dependentKeys: ['model.i18n.locale']
  }),
  answerType: [
    validator('presence', {
      presence: true,
      dependentKeys: ['model.i18n.locale']
    }),
    validator('inclusion', {
      in: ['YesNo', 'YesNoMaybe', 'FreeText'],
      dependentKeys: ['model.i18n.locale']
    })
  ],
  forceAnswer: validator('presence', true)
});
github adiwg / mdEditor / app / pods / components / object / md-source / component.js View on Github external
getWithDefault,
  get
} from '@ember/object';
import {
  alias
} from '@ember/object/computed';
import {
  once
} from '@ember/runloop';
import {
  validator,
  buildValidations
} from 'ember-cp-validations';
import uuidV4 from "uuid/v4";

const Validations = buildValidations({
  'description': [
    validator('presence', {
      presence: true,
      ignoreBlank: true
    })
  ]
});

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

    let model = get(this, 'model');

    once(this, function () {
      set(model, 'sourceId', getWithDefault(model, 'sourceId', uuidV4()));
github adiwg / mdEditor / app / models / schema.js View on Github external
import Ajv from 'ajv';
import * as ajvErrors from  'ajv-errors';
import * as draft4 from 'ajv/lib/refs/json-schema-draft-04';

const ajvOptions = {
  verbose: true,
  allErrors: true,
  jsonPointers: true,
  removeAdditional: false,
  schemaId: 'auto'
};

const regex =
  /^(?:(?:(?:https?|ftp):)?\/\/)(?:\S+(?::\S*)?@)?(?:(?!(?:10|127)(?:\.\d{1,3}){3})(?!(?:169\.254|192\.168)(?:\.\d{1,3}){2})(?!172\.(?:1[6-9]|2\d|3[0-1])(?:\.\d{1,3}){2})(?:[1-9]\d?|1\d\d|2[01]\d|22[0-3])(?:\.(?:1?\d{1,2}|2[0-4]\d|25[0-5])){2}(?:\.(?:[1-9]\d?|1\d\d|2[0-4]\d|25[0-4]))|(?:(?:[a-z0-9\u00a1-\uffff][a-z0-9\u00a1-\uffff_-]{0,62})?[a-z0-9\u00a1-\uffff]\.)+(?:[a-z\u00a1-\uffff]{2,}\.?))(?::\d{2,5})?(?:[/?#]\S*)?$/i;

const Validations = buildValidations({
  'title': validator(
    'presence', {
      presence: true,
      ignoreBlank: true,
    }),
  'description': validator('presence', {
    presence: true,
    ignoreBlank: true
  }),
  'schemaType': [
    validator('presence', true),
    validator('inclusion', {
      description: 'This value',
      in: ['record', 'contact', 'dictionary']
    })
  ],
github ilios / frontend / app / components / new-user.js View on Github external
import Component from '@ember/component';
import NewUser from 'ilios/mixins/newuser';
import { validator, buildValidations } from 'ember-cp-validations';

const Validations = buildValidations({
  firstName: [
    validator('presence', true),
    validator('length', {
      max: 50
    })
  ],
  middleName: [
    validator('length', {
      max: 20
    })
  ],
  lastName: [
    validator('presence', true),
    validator('length', {
      max: 50
    })
github apache / ambari / contrib / views / wfmanager / src / main / resources / ui / app / components / fs-action.js View on Github external
*    The ASF licenses this file to You under the Apache License, Version 2.0
*    (the "License"); you may not use this file except in compliance with
*    the License.  You may obtain a copy of the License at
*
*        http://www.apache.org/licenses/LICENSE-2.0
*
*    Unless required by applicable law or agreed to in writing, software
*    distributed under the License is distributed on an "AS IS" BASIS,
*    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
*    See the License for the specific language governing permissions and
*    limitations under the License.
*/
import Ember from 'ember';
import { validator, buildValidations } from 'ember-cp-validations';

const Validations = buildValidations({
  'actionModel.fsOps': {
    validators: [
      validator('fs-action-validator', {
        dependentKeys: ['actionModel.fsOps.@each']
      })
    ]
  }
});

export default Ember.Component.extend(Validations, {
  fileBrowser: Ember.inject.service('file-browser'),
  setUp: function() {
    if (this.get('actionModel.fsOps') === undefined) {
      this.set("actionModel.fsOps", Ember.A([]));
    }
    if (this.get('actionModel.configuration') === undefined) {