Skip to content

Instantly share code, notes, and snippets.

@jimsynz
Last active August 29, 2015 14:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jimsynz/600a087f1448ae01b065 to your computer and use it in GitHub Desktop.
Save jimsynz/600a087f1448ae01b065 to your computer and use it in GitHub Desktop.
App.InputLabelComponent = Em.Component.extend
tagName: 'label'
classNameBindings: [':right', ':inline', 'hasErrors:error']
attributeBindings: 'for'
init: ->
@_super()
# We do this here because we don't know the name of the
# key we depend on at creation time.
error_prop = "on.errors.#{@get('for')}"
Em.defineProperty(@, 'errors', Em.computed(error_prop, -> @get(error_prop)))
hasErrors: (->
@get('errors.length') > 0
).property('errors.length')
{{input value=value name=for typeBinding="type" classBinding="hasErrors:error" placeholder=placeholder dropdown=dropdown}}
{{#if hasErrors}}
<div class="small error">
{{#each error in errors}}
{{error}}
<br />
{{/each}}
</div>
{{/if}}
App.ValidInputComponent = Em.Component.extend
init: ->
@_super()
# We do this here because we don't know the name of the
# key we depend on at creation time.
error_prop = "on.errors.#{@get('for')}"
value_prop = "on.#{@get('for')}"
Em.defineProperty(@, 'errors', Em.computed(error_prop, -> @get(error_prop)))
Em.defineProperty(@, 'value', Em.computed(value_prop, (key,value)->
if value?
@set(value_prop, value)
else
@get(value_prop)
))
type: 'text'
hasErrors: (->
@get('errors.length') > 0
).property('errors.length')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment