Created
June 28, 2012 04:02
-
-
Save bradleypriest/3008971 to your computer and use it in GitHub Desktop.
Magic Ember Form
This file contains hidden or 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.MagicFormView = Ember.ContainerView.extend | |
tagName: 'form' | |
setChildViews: ( -> | |
if @get('object') | |
childViews = @get('childViews') | |
childViews.invoke('removeFromParent') | |
# Add a text field for each attribute | |
attributeMap = Ember.getPath(@getPath('object.constructor'), 'attributes') | |
attributeMap.forEach( (attribute) -> | |
property = @get(attribute) | |
view = Ember.TextField.create | |
valueBinding: attribute | |
type: Ember.get(property, 'type') | |
childViews.pushObject(view) | |
, attributeMap) | |
# Add a button | |
childViews.pushObject Ember.View.create | |
tagName: 'button' | |
template: Ember.Handlebars.compile("Submit") | |
).observes("object") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment