Sha256: f85dc76b64fb8501d7ab4efc5e38beb38974d32c10ca88d3fe95d3c8f0c0e2b9

Contents?: true

Size: 1.09 KB

Versions: 32

Compression:

Stored size: 1.09 KB

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: @defaultValue()
      name: @name()

    if @props.type in ['textarea', 'select']
      t = @props.type

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

    <Rev.Components.Input key="#{ @props.model.cid }-#{ @name() }"  dom={t} {...form_params} {...@props} onChange={ @onChange } error={ @state.error } onBlur={ @onBlur }>
      { @props.children }
    </Rev.Components.Input>

  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

32 entries across 32 versions & 1 rubygems

Version Path
revelry_core-0.1.12.6 app/assets/javascripts/revelry/ui/forms/ModelForm/ModelInput.js.cjsx
revelry_core-0.1.12.5 app/assets/javascripts/revelry/ui/forms/ModelForm/ModelInput.js.cjsx
revelry_core-0.1.12.4 app/assets/javascripts/revelry/ui/forms/ModelForm/ModelInput.js.cjsx
revelry_core-0.1.12.3 app/assets/javascripts/revelry/ui/forms/ModelForm/ModelInput.js.cjsx
revelry_core-0.1.12.2 app/assets/javascripts/revelry/ui/forms/ModelForm/ModelInput.js.cjsx
revelry_core-0.1.12.0 app/assets/javascripts/revelry/ui/forms/ModelForm/ModelInput.js.cjsx
revelry_core-0.1.11.6 app/assets/javascripts/revelry/ui/forms/ModelForm/ModelInput.js.cjsx
revelry_core-0.1.11.5 app/assets/javascripts/revelry/ui/forms/ModelForm/ModelInput.js.cjsx
revelry_core-0.1.11.2 app/assets/javascripts/revelry/ui/forms/ModelForm/ModelInput.js.cjsx
revelry_core-0.1.11.1 app/assets/javascripts/revelry/ui/forms/ModelForm/ModelInput.js.cjsx
revelry_core-0.1.11.0 app/assets/javascripts/revelry/ui/forms/ModelForm/ModelInput.js.cjsx
revelry_core-0.1.10.7 app/assets/javascripts/revelry/ui/forms/ModelForm/ModelInput.js.cjsx
revelry_core-0.1.10.6 app/assets/javascripts/revelry/ui/forms/ModelForm/ModelInput.js.cjsx
revelry_core-0.1.10.5 app/assets/javascripts/revelry/ui/forms/ModelForm/ModelInput.js.cjsx
revelry_core-0.1.10.4 app/assets/javascripts/revelry/ui/forms/ModelForm/ModelInput.js.cjsx
revelry_core-0.1.10.3 app/assets/javascripts/revelry/ui/forms/ModelForm/ModelInput.js.cjsx
revelry_core-0.1.10.2 app/assets/javascripts/revelry/ui/forms/ModelForm/ModelInput.js.cjsx
revelry_core-0.1.10.1 app/assets/javascripts/revelry/ui/forms/ModelForm/ModelInput.js.cjsx
revelry_core-0.1.10.0 app/assets/javascripts/revelry/ui/forms/ModelForm/ModelInput.js.cjsx
revelry_core-0.1.9.2 app/assets/javascripts/revelry/ui/forms/ModelForm/ModelInput.js.cjsx