Created
March 11, 2016 20:15
-
-
Save bcardarella/1514ec4958caec0a72cd to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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', /@/) | |
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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