Files
ember-cli-dunlop/app/components/validated-attribute.coffee
T
2017-12-21 11:42:41 +01:00

21 lines
713 B
CoffeeScript

import Ember from 'ember'
export default Ember.Component.extend
classNameBindings: ['hasError:error', 'containerClass']
classNames: ['field']
disabled: false
error_text: 'Please set...'
containerClass: Ember.computed 'attribute', ->
return 'validated-attribute' unless record = @get('changeset._content')
record_name = record.constructor.modelName || 'record'
"validated-attribute-#{record_name}-#{Ember.String.dasherize(@get('attribute'))}".replace(/[\W_]/g, '-')
init: ->
@_super()
Ember.defineProperty(@, "hasError", Ember.computed.bool("changeset.error.#{@get("attribute")}"))
actions:
validateAttribute: (changeset, attribute) ->
changeset.validate(attribute)