Sha256: 52e24994162681cb8d1afd4b7ade8943126248535559f942cb14e3058bf13d7b

Contents?: true

Size: 1.08 KB

Versions: 46

Compression:

Stored size: 1.08 KB

Contents

Rev.pullInto(this) 'Form'

# A form that works with Backbone models to do AJAXy submission & backbone
# validation
Rev.registerComponent 'ModelForm',
  mixins: [Backbone.Events, Rev.Mixins.BackboneStore]

  propTypes:
    model: React.PropTypes.object.isRequired

  getInitialState: ->
    state =
      errors: null

  render: ->
    <Form method="POST" onSubmit={ @onSubmit } action={ @formAction() } className={ @props.className } encType="multipart/form-data">
      { @props.children  }
    </Form>

  formAction: ->
    if @props.action?
      return @props.action
    @props.model.url()

  formMethod: ->
    if @props.method?
      return @props.method

    if @props.model?
      return if @props.model.isNew() then 'POST' else 'PATCH'

    'POST'

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

  componentDidUnmount: ->
    @stopListening @props.model

  onError: (model, resp, options)->
    @setState errors: resp.responseJSON.errors

  onSubmit: (e)->
    e.preventDefault()
    @props.model.save null,
      success: @props.onSuccess
      error: @props.onError

Version data entries

46 entries across 46 versions & 1 rubygems

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