Sha256: 4509e76d6b6604412e08fb5350f4b6f69c994695948206fcc7decf89784fd258

Contents?: true

Size: 1004 Bytes

Versions: 12

Compression:

Stored size: 1004 Bytes

Contents

Rev.registerComponent 'ModelInput',
  mixins: [ Rev.App.Mixins.ModelInputMixin, Backbone.Events ]

  propTypes:
    field: React.PropTypes.string.isRequired
    model: React.PropTypes.object.isRequired
    name: React.PropTypes.string
    baseName: React.PropTypes.string

  getInitialState: ->
    error: null

  render: ->
    form_params =
      defaultValue: @value()
      name: @name()

    if @props.type == 'textarea'
      t = 'textarea'

    if @isCheckbox()
      form_params['defaultChecked'] = @value()

    <Rev.Components.Input dom={t} {...form_params} {...@props} onChange={ @onChange } error={ @state.error } onBlur={ @onBlur } />

  componentDidMount: ->
    @listenTo @props.model, 'error', @onError

  componentDidUnmount: ->
    @stopListening()

  onError: (model, resp, options)->
    errors = resp.responseJSON.errors
    if errors && errors[@props.field]
      @setState error: errors[@props.field].join ' and '

  onChange: (e)->
    @setState error: null
    @onFieldChange(e)

Version data entries

12 entries across 12 versions & 1 rubygems

Version Path
revelry_core-0.1.6.4 app/assets/javascripts/revelry/ui/forms/ModelForm/ModelInput.js.cjsx
revelry_core-0.1.6.3 app/assets/javascripts/revelry/ui/forms/ModelForm/ModelInput.js.cjsx
revelry_core-0.1.6.2 app/assets/javascripts/revelry/ui/forms/ModelForm/ModelInput.js.cjsx
revelry_core-0.1.6.1 app/assets/javascripts/revelry/ui/forms/ModelForm/ModelInput.js.cjsx
revelry_core-0.1.5 app/assets/javascripts/revelry/ui/forms/ModelForm/ModelInput.js.cjsx
revelry_core-0.1.4 app/assets/javascripts/revelry/ui/forms/ModelForm/ModelInput.js.cjsx
revelry_core-0.1.3 app/assets/javascripts/revelry/ui/forms/ModelForm/ModelInput.js.cjsx
revelry_core-0.1.2 app/assets/javascripts/revelry/ui/forms/ModelForm/ModelInput.js.cjsx
revelry_core-0.1.1 app/assets/javascripts/revelry/ui/forms/ModelForm/ModelInput.js.cjsx
revelry_core-0.1.0 app/assets/javascripts/revelry/ui/forms/ModelForm/ModelInput.js.cjsx
revelry_core-0.0.1 app/assets/javascripts/revelry/ui/forms/ModelForm/ModelInput.js.cjsx
revelry_core-0.0.0 app/assets/javascripts/revelry/ui/forms/ModelForm/ModelInput.js.cjsx