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 quickstart-validations.js
import {
validatePresence,
validateLength,
validateInclusion
} from "ember-changeset-validations/validators";
export default {
firstName: [validatePresence(true), validateLength({ min: 3, max: 40 })],
lastName: [validatePresence(true), validateLength({ min: 3, max: 40 })],
aboutMe: [validateLength({ allowBlank: true, max: 200 })],
country: [validatePresence(true)],
gender: [validatePresence(true)],
terms: [
validateInclusion({
list: [true],
message: "Please accept the terms and conditions!"
})
],
color: [validatePresence(true)]
};
// END-SNIPPET
return true;
}
let result = validate('presence', value, options, null, key);
if (typeof result === 'boolean' || typeof result === 'string') {
return result;
} else {
// We flipped the meaning behind `present` and `blank` so switch the two
if (result.type === 'present') {
result.type = 'blank';
} else if (result.type === 'blank') {
result.type = 'present';
}
return buildMessage(key, result);
}
};
}
}
}
const result = validate('presence', value, options, null, key);
if (typeof result === 'boolean' || typeof result === 'string') {
return result;
}
// We flipped the meaning behind `present` and `blank` so switch the two
if (result.type === 'present') {
result.type = 'blank';
} else if (result.type === 'blank') {
result.type = 'present';
}
return buildMessage(key, result);
};
}
export default function getMessages(moduleMap = requirejs.entries, useCache = true) {
let messagesModule = defaultMessages;
if (useCache && isPresent(cachedRef)) {
return cachedRef;
}
let moduleKey = emberArray(keys(moduleMap))
.find((key) => key === moduleName);
if (isPresent(moduleKey)) {
// Merge the user specified messages with the defaults
messagesModule = withDefaults(requireModule(moduleKey).default, messagesModule);
}
cachedRef = messagesModule;
return messagesModule;
}
init() {
this._super(...arguments);
const user = this.get('user');
this.changeset = new Changeset(user, lookupValidator(this.UserValidations), this.UserValidations);
},
init() {
this._super(...arguments);
this.changeset = new Changeset(model, lookupValidator(validation), validation);
},
import { validatePresence, validateLength } from 'ember-changeset-validations/validators';
import validateSometimes from 'ember-changeset-conditional-validations/validators/sometimes';
export default {
paymentMethod: validatePresence(true),
creditCardNumber: validateSometimes([
validatePresence(true),
validateLength({ is: 16 })
], function() {
return this.get('paymentMethod') === 'credit-card';
})
};
import Component from '@ember/component';
import { validatePresence, validateLength } from 'ember-changeset-validations/validators';
const rulez = {
firstName: [
validatePresence(true),
validateLength({ min: 2 })
],
lastName: [
validatePresence(true),
validateLength({ min: 2 })
]
};
const schema = {
firstName: null,
lastName: null
};
export default Component.extend({
rulez,
schema
});
model() {
let store = get(this, 'store');
let media = store.createRecord('media', {
title: 'a title',
url: 'http'
});
let validatorFn = lookupValidator(MediaValidations);
let changeset = new Changeset(media, validatorFn, MediaValidations);
changeset.validate();
return changeset;
}
});
import {
validatePresence,
validateLength
} from "ember-changeset-validations/validators";
export default {
description: [validateLength({ max: 300 })],
file: [validatePresence(true)]
};