Skip to content

Instantly share code, notes, and snippets.

@bradleypriest
Created June 28, 2012 04:02
Show Gist options
  • Save bradleypriest/3008971 to your computer and use it in GitHub Desktop.
Save bradleypriest/3008971 to your computer and use it in GitHub Desktop.
Magic Ember Form
{{view App.MagicFormView objectBinding="post"}}
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