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.3 app/assets/javascripts/revelry/ui/forms/ModelForm/ModelForm.js.cjsx
revelry_core-0.1.2 app/assets/javascripts/revelry/ui/forms/ModelForm/ModelForm.js.cjsx
revelry_core-0.1.1 app/assets/javascripts/revelry/ui/forms/ModelForm/ModelForm.js.cjsx
revelry_core-0.1.0 app/assets/javascripts/revelry/ui/forms/ModelForm/ModelForm.js.cjsx
revelry_core-0.0.1 app/assets/javascripts/revelry/ui/forms/ModelForm/ModelForm.js.cjsx
revelry_core-0.0.0 app/assets/javascripts/revelry/ui/forms/ModelForm/ModelForm.js.cjsx