Created
April 14, 2015 12:47
-
-
Save anonymous/9e1229d731a1f64a84a8 to your computer and use it in GitHub Desktop.
Ember Starter Kit // source http://emberjs.jsbin.com/cisuko
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
<!DOCTYPE html> | |
<html> | |
<head> | |
<script src="http://code.jquery.com/jquery.min.js"></script> | |
<link href="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.2/css/bootstrap.min.css" rel="stylesheet" type="text/css" /> | |
<script src="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.2/js/bootstrap.min.js"></script> | |
<meta charset="utf-8"> | |
<title>Ember Starter Kit</title> | |
<link rel="stylesheet" href="http://cdnjs.cloudflare.com/ajax/libs/normalize/3.0.1/normalize.css"> | |
<script src="http://builds.emberjs.com/tags/v1.10.0/ember-template-compiler.js"></script> | |
<script src="http://builds.emberjs.com/tags/v1.10.0/ember.debug.js"></script> | |
<script src="http://builds.dockyard.com.s3.amazonaws.com/ember-validations/canary/ember-validations.js"></script> | |
<style id="jsbin-css"> | |
/* Put your CSS here */ | |
html, body { | |
margin: 20px; | |
} | |
</style> | |
</head> | |
<body> | |
<script type="text/x-handlebars"> | |
{{outlet}} | |
</script> | |
<script type="text/x-handlebars" data-template-name="index"> | |
<form> | |
<fieldset> | |
<legend>You</legend> | |
<div {{bind-attr class=":form-group nameValid::has-error"}}> | |
<label for="name" class="control-label">Name</label> | |
{{input value=model.name id="name" class="form-control"}} | |
<span class="help-block">{{nameError}}</span> | |
</div> | |
<div {{bind-attr class=":form-group ageValid::has-error"}}> | |
<label for="age" class="control-label">Age</label> | |
{{input type="number" value=model.age id="age" class="form-control"}} | |
<span class="help-block">{{ageError}}</span> | |
</div> | |
<button class="btn btn-primary" {{bind-attr disabled="isInvalid"}}> | |
Submit | |
</button> | |
</fieldset> | |
</form> | |
</script> | |
<script id="jsbin-javascript"> | |
App = Ember.Application.create(); | |
App.Router.map(function() { | |
// put your routes here | |
}); | |
App.IndexRoute = Ember.Route.extend({ | |
model: function() { | |
return App.Person.create(); | |
} | |
}); | |
// Our model | |
App.Person = Ember.Object.extend({ | |
name: undefined, | |
age: undefined | |
}); | |
// Controller | |
App.IndexController = Ember.Controller.extend(Ember.Validations.Mixin, { | |
name: Ember.computed.alias('model.name'), | |
age: Ember.computed.alias('model.age'), | |
validations: { | |
name: { | |
presence: true | |
}, | |
age: { | |
numericality: true | |
} | |
}, | |
nameValid: function(){ | |
return this.get('errors.name.length') === 0; | |
}.property('errors.name.[]'), | |
ageValid: function(){ | |
return this.get('errors.age.length') === 0; | |
}.property('errors.age.[]'), | |
nameError: function() { | |
return this.get('errors.name').join(", "); | |
}.property('nameValid'), | |
ageError: function() { | |
return this.get('errors.age').join(", "); | |
}.property('ageValid') | |
}); | |
</script> | |
<script id="jsbin-source-html" type="text/html"><!DOCTYPE html> | |
<html> | |
<head> | |
<script src="//code.jquery.com/jquery.min.js"><\/script> | |
<link href="//maxcdn.bootstrapcdn.com/bootstrap/3.3.2/css/bootstrap.min.css" rel="stylesheet" type="text/css" /> | |
<script src="//maxcdn.bootstrapcdn.com/bootstrap/3.3.2/js/bootstrap.min.js"><\/script> | |
<meta charset="utf-8"> | |
<title>Ember Starter Kit</title> | |
<link rel="stylesheet" href="http://cdnjs.cloudflare.com/ajax/libs/normalize/3.0.1/normalize.css"> | |
<script src="http://builds.emberjs.com/tags/v1.10.0/ember-template-compiler.js"><\/script> | |
<script src="http://builds.emberjs.com/tags/v1.10.0/ember.debug.js"><\/script> | |
<script src="http://builds.dockyard.com.s3.amazonaws.com/ember-validations/canary/ember-validations.js"><\/script> | |
</head> | |
<body> | |
<script type="text/x-handlebars"> | |
{{outlet}} | |
<\/script> | |
<script type="text/x-handlebars" data-template-name="index"> | |
<form> | |
<fieldset> | |
<legend>You</legend> | |
<div {{bind-attr class=":form-group nameValid::has-error"}}> | |
<label for="name" class="control-label">Name</label> | |
{{input value=model.name id="name" class="form-control"}} | |
<span class="help-block">{{nameError}}</span> | |
</div> | |
<div {{bind-attr class=":form-group ageValid::has-error"}}> | |
<label for="age" class="control-label">Age</label> | |
{{input type="number" value=model.age id="age" class="form-control"}} | |
<span class="help-block">{{ageError}}</span> | |
</div> | |
<button class="btn btn-primary" {{bind-attr disabled="isInvalid"}}> | |
Submit | |
</button> | |
</fieldset> | |
</form> | |
<\/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.Router.map(function() { | |
// put your routes here | |
}); | |
App.IndexRoute = Ember.Route.extend({ | |
model: function() { | |
return App.Person.create(); | |
} | |
}); | |
// Our model | |
App.Person = Ember.Object.extend({ | |
name: undefined, | |
age: undefined | |
}); | |
// Controller | |
App.IndexController = Ember.Controller.extend(Ember.Validations.Mixin, { | |
name: Ember.computed.alias('model.name'), | |
age: Ember.computed.alias('model.age'), | |
validations: { | |
name: { | |
presence: true | |
}, | |
age: { | |
numericality: true | |
} | |
}, | |
nameValid: function(){ | |
return this.get('errors.name.length') === 0; | |
}.property('errors.name.[]'), | |
ageValid: function(){ | |
return this.get('errors.age.length') === 0; | |
}.property('errors.age.[]'), | |
nameError: function() { | |
return this.get('errors.name').join(", "); | |
}.property('nameValid'), | |
ageError: function() { | |
return this.get('errors.age').join(", "); | |
}.property('ageValid') | |
});</script></body> | |
</html> |
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
/* Put your CSS here */ | |
html, body { | |
margin: 20px; | |
} |
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
App = Ember.Application.create(); | |
App.Router.map(function() { | |
// put your routes here | |
}); | |
App.IndexRoute = Ember.Route.extend({ | |
model: function() { | |
return App.Person.create(); | |
} | |
}); | |
// Our model | |
App.Person = Ember.Object.extend({ | |
name: undefined, | |
age: undefined | |
}); | |
// Controller | |
App.IndexController = Ember.Controller.extend(Ember.Validations.Mixin, { | |
name: Ember.computed.alias('model.name'), | |
age: Ember.computed.alias('model.age'), | |
validations: { | |
name: { | |
presence: true | |
}, | |
age: { | |
numericality: true | |
} | |
}, | |
nameValid: function(){ | |
return this.get('errors.name.length') === 0; | |
}.property('errors.name.[]'), | |
ageValid: function(){ | |
return this.get('errors.age.length') === 0; | |
}.property('errors.age.[]'), | |
nameError: function() { | |
return this.get('errors.name').join(", "); | |
}.property('nameValid'), | |
ageError: function() { | |
return this.get('errors.age').join(", "); | |
}.property('ageValid') | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment