Skip to content

Instantly share code, notes, and snippets.

@Sivli-Embir
Last active August 29, 2015 14:16
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 Sivli-Embir/d37d25282c1126d0e952 to your computer and use it in GitHub Desktop.
Save Sivli-Embir/d37d25282c1126d0e952 to your computer and use it in GitHub Desktop.
<template name='form'>
<input name='email' value={{email}}>
{{#with validate 'email'}}
{{message}}
{{/with}}
</template>
EmailForm = new ShadowModel({
collection: new Mongo.Collection('example'),
fields: { //basically a transform + schema for instances
email: function (value) {
var email = someEmailValidator(value) //readme shortcut -_^
if (email) {
if (email == 'gmail') {
return this.valid('is a Gmail email')
} else if (email == 'apple') {
return this.valid('is an Apple email')
} else { //and so on
return this.valid('is email')
}
} else {
return this.invalid('must be an email') //you would want to be more descriptive...
}
},
...
}
}
Template.form.helpers({
data: function () {
return EmailForm.new()
}
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment