Skip to content

Instantly share code, notes, and snippets.

@bcardarella
Created March 11, 2016 20:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bcardarella/1514ec4958caec0a72cd to your computer and use it in GitHub Desktop.
Save bcardarella/1514ec4958caec0a72cd to your computer and use it in GitHub Desktop.
import { presence, length, confirmation, format} from 'ember-validations/validators';
errors: computed('name', 'email', 'password', 'passwordConfirmation', function() {
let user = get(this, 'model');
return user
::presence('name', 'email', 'password')
::length('password', { greaterThan: 8 })
::confirmation('password')
::format('email', /@/)
})
const {
isBlank
} = Ember;
export function presence(context, ...properties, options = {}) {
let set = convertToSet(context);
context.model.changedAttributes()
::Object.keys()
::intersect(properties)
.forEach(function(prop) {
if (isBlank(get(context.model, prop))) {
setError(set, prop, 'presence');
}
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment