Skip to content

Instantly share code, notes, and snippets.

@sakozz
Created January 3, 2015 16:35
Show Gist options
  • Save sakozz/1846d6bcab2a1de92e36 to your computer and use it in GitHub Desktop.
Save sakozz/1846d6bcab2a1de92e36 to your computer and use it in GitHub Desktop.
Ember easy-form with validations // source http://jsbin.com/suhuju
<!DOCTYPE html>
<html>
<head>
<meta name="description" content="ember validations" />
<script src="http://code.jquery.com/jquery.min.js"></script>
<link href="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.1/css/bootstrap.min.css" rel="stylesheet" type="text/css" />
<script src="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.1/js/bootstrap.min.js"></script>
<meta charset="utf-8">
<title>Ember Starter Kit</title>
<style id="jsbin-css">
/* Put your CSS here */
html, body {
margin: 20px;
}
</style>
</head>
<body>
<script type="text/x-handlebars">
<h2>Welcome to Ember.js</h2>
{{outlet}}
</script>
<script type="text/x-handlebars" data-template-name="index">
<h2>Sign up</h2>
<div class="page-content">
{{#form-for controller class="form-horizontal"}}
{{input email as="email" }}
{{input password as="password"}}
{{input passwordConfirmation as="password"}}
{{submit class="btn btn-primary"}}
{{/form-for}}
<div>
</script>
<script src="http://builds.handlebarsjs.com.s3.amazonaws.com/handlebars-v1.3.0.js"></script>
<script src="http://builds.emberjs.com/tags/v1.5.0/ember.js"></script>
<script src="http://rawgithub.com/ember-addons/bootstrap-for-ember/master/dist/js/bs-core.max.js"></script>
<script src="http://rawgithub.com/ember-addons/bootstrap-for-ember/master/dist/js/bs-modal.max.js"></script>
<script src="http://rawgithub.com/ember-addons/bootstrap-for-ember/master/dist/js/bs-button.max.js"></script>
<script src="http://builds.emberjs.com.s3.amazonaws.com/beta/daily/20130929/ember-data.prod.js"></script>
<script src="http://builds.dockyard.com.s3.amazonaws.com/ember-easyForm/stable/ember-easyForm.js"></script>
<script src="http://builds.dockyard.com.s3.amazonaws.com/ember-validations/ember-validations-latest.js"></script>
<script id="jsbin-javascript">
App = Ember.Application.create();
App.ApplicationStore = DS.Store.extend({});
App.User = DS.Model.extend({
email: DS.attr(),
password: DS.attr()
});
App.Router.map(function() {
this.resource('users');
});
App.IndexRoute = Ember.Route.extend({
model: function() {
return this.store.createRecord('user');
}
});
App.IndexController= Ember.ObjectController.extend(Ember.Validations.Mixin, {
actions: {
submit: function(){
alert('submitted');
}
},
validations: {
email: {
presence: true,
format: { with: /^[\w+\-.]+@[a-z\d\-.]+\.[a-z]+$/i, message: 'Invalid e-mail address'}
},
password: {
length: { minimum: 8, maximum: 16 },
confirmation: {message: 'Please make sure password matches '},
presence: true
},
passwordConfirmation: {
presence: {
message: 'please confirm password'
}
}
}
});
</script>
<script id="jsbin-source-html" type="text/html"><!DOCTYPE html>
<html>
<head>
<meta name="description" content="ember validations" />
<script src="//code.jquery.com/jquery.min.js"><\/script>
<link href="//maxcdn.bootstrapcdn.com/bootstrap/3.3.1/css/bootstrap.min.css" rel="stylesheet" type="text/css" />
<script src="//maxcdn.bootstrapcdn.com/bootstrap/3.3.1/js/bootstrap.min.js"><\/script>
<meta charset="utf-8">
<title>Ember Starter Kit</title>
</head>
<body>
<script type="text/x-handlebars">
<h2>Welcome to Ember.js</h2>
{{outlet}}
<\/script>
<script type="text/x-handlebars" data-template-name="index">
<h2>Sign up</h2>
<div class="page-content">
{{#form-for controller class="form-horizontal"}}
{{input email as="email" }}
{{input password as="password"}}
{{input passwordConfirmation as="password"}}
{{submit class="btn btn-primary"}}
{{/form-for}}
<div>
<\/script>
<script src="http://builds.handlebarsjs.com.s3.amazonaws.com/handlebars-v1.3.0.js"><\/script>
<script src="http://builds.emberjs.com/tags/v1.5.0/ember.js"><\/script>
<script src="http://rawgithub.com/ember-addons/bootstrap-for-ember/master/dist/js/bs-core.max.js"><\/script>
<script src="http://rawgithub.com/ember-addons/bootstrap-for-ember/master/dist/js/bs-modal.max.js"><\/script>
<script src="http://rawgithub.com/ember-addons/bootstrap-for-ember/master/dist/js/bs-button.max.js"><\/script>
<script src="http://builds.emberjs.com.s3.amazonaws.com/beta/daily/20130929/ember-data.prod.js"><\/script>
<script src="http://builds.dockyard.com.s3.amazonaws.com/ember-easyForm/stable/ember-easyForm.js"><\/script>
<script src="http://builds.dockyard.com.s3.amazonaws.com/ember-validations/ember-validations-latest.js"><\/script>
</body>
</html>
</script>
<script id="jsbin-source-css" type="text/css">/* Put your CSS here */
html, body {
margin: 20px;
}
</script>
<script id="jsbin-source-javascript" type="text/javascript">App = Ember.Application.create();
App.ApplicationStore = DS.Store.extend({});
App.User = DS.Model.extend({
email: DS.attr(),
password: DS.attr()
});
App.Router.map(function() {
this.resource('users');
});
App.IndexRoute = Ember.Route.extend({
model: function() {
return this.store.createRecord('user');
}
});
App.IndexController= Ember.ObjectController.extend(Ember.Validations.Mixin, {
actions: {
submit: function(){
alert('submitted');
}
},
validations: {
email: {
presence: true,
format: { with: /^[\w+\-.]+@[a-z\d\-.]+\.[a-z]+$/i, message: 'Invalid e-mail address'}
},
password: {
length: { minimum: 8, maximum: 16 },
confirmation: {message: 'Please make sure password matches '},
presence: true
},
passwordConfirmation: {
presence: {
message: 'please confirm password'
}
}
}
});
</script></body>
</html>
/* Put your CSS here */
html, body {
margin: 20px;
}
App = Ember.Application.create();
App.ApplicationStore = DS.Store.extend({});
App.User = DS.Model.extend({
email: DS.attr(),
password: DS.attr()
});
App.Router.map(function() {
this.resource('users');
});
App.IndexRoute = Ember.Route.extend({
model: function() {
return this.store.createRecord('user');
}
});
App.IndexController= Ember.ObjectController.extend(Ember.Validations.Mixin, {
actions: {
submit: function(){
alert('submitted');
}
},
validations: {
email: {
presence: true,
format: { with: /^[\w+\-.]+@[a-z\d\-.]+\.[a-z]+$/i, message: 'Invalid e-mail address'}
},
password: {
length: { minimum: 8, maximum: 16 },
confirmation: {message: 'Please make sure password matches '},
presence: true
},
passwordConfirmation: {
presence: {
message: 'please confirm password'
}
}
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment