Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
// 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 */) {
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
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: {
*
* ## 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}
*/
* 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'
});
* 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
*
* ```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'
});
* ## 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'
});
* ## 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
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
});
},