Created
September 2, 2012 20:10
-
-
Save jcf/3604118 to your computer and use it in GitHub Desktop.
Ember.js inputs with labels via a custom ContainerView instance
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.FieldView = Em.ContainerView.extend | |
tagName: '' | |
type: 'text' | |
label: null | |
value: null | |
size: '30' | |
required: null | |
requiredAttribute: (-> | |
if @get('required') == 'true' then '' else null | |
).property('required') | |
childViews: 'labelView dataView'.w() | |
labelView: Em.View.extend | |
tagName: 'label' | |
attributeBindings: ['for'] | |
forBinding: 'parentView.dataView.elementId' | |
textBinding: 'parentView.label' | |
requiredBinding: 'parentView.required' | |
defaultTemplate: Em.Handlebars.compile('{{view.text}}{{#if view.required}}<abbr title="Required">*</abbr>{{/if}}') | |
dataView: Em.TextField.extend | |
attributeBindings: 'type value size placeholder required'.w() | |
typeBinding: 'parentView.type' | |
sizeBinding: 'parentView.size' | |
valueBinding: 'parentView.value' | |
requiredBinding: 'parentView.requiredAttribute' | |
App.TextField = App.FieldView.extend() | |
App.TextArea = App.FieldView.extend | |
dataView: Em.TextArea.extend() | |
App.EmailField = App.FieldView.extend | |
type: 'email' | |
App.PasswordField = App.FieldView.extend | |
type: 'password' | |
App.NumberField = App.FieldView.extend | |
dataView: Em.TextField.extend | |
type: 'number' | |
attributeBindings: 'type value size placeholder min max step required'.w() | |
minBinding: 'parentView.min' | |
maxBinding: 'parentView.max' | |
sizeBinding: 'parentView.size' | |
valueBinding: 'parentView.value' | |
requiredBinding: 'parentView.requiredAttribute' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Renamed
valueSize
to justsize
.