Sha256: 675f7eb989122cd43604574007439cae2db7eddb6afb003ea590647573db72c0

Contents?: true

Size: 1.9 KB

Versions: 32

Compression:

Stored size: 1.9 KB

Contents

Rev.pullInto(this) 'Row', 'Col', 'ModelForm', 'ModelInput', 'ModelProgressIndicator', 'Textarea', 'Switch'

class ExampleModel extends Backbone.Model
  url: ->

  # Fake this up just for the demo. None of this is _actually required_ in a
  # real app using real Backbone and a real API
  sync: ->
    @trigger 'request'
    setTimeout =>
      if @validateName.bind(@)()
        @trigger 'error', @, { responseJSON: { errors: { name: [@validateName.bind(@)()] } }}, {}
      else
        @trigger 'sync'
    , 1000

  validateName: ->
    if _.isEmpty(@get('name'))
      return "is required"

Rev.registerExample 'ModelForm',
  getInitialState: ->
    model: new ExampleModel()

  componentDidMount: ->
    @state.model.on 'all', @modelUpdated

  componentWillUnmount: ->
    @state.model.off 'all', @modelUpdated

  modelUpdated: ->
    @forceUpdate()

  render: ->
    <div>
      <div>
        { JSON.stringify(@state.model.attributes) }
      </div>
      <ModelForm model={ @state.model }>
        <Row>
          <Col>
            <ModelProgressIndicator model={ @state.model } started='Click "Try it out"' requested='Saving…' errored='ERROR ERROR' synced='Model saved!' />
          </Col>
        </Row>
        <Row>
          <Col><ModelInput field="name" type="text" placeholder="This field is required" model={ @state.model } /></Col>
          <Col><ModelInput field="optional" type="text" placeholder="This field is optional" model={ @state.model } /></Col>
          <Col><ModelInput field="textarea" type="textarea" model={ @state.model } /></Col>
          <Col>
            <ModelInput field="select" type="select" model={ @state.model }>
              <option></option>
              <option value="option1">Option 1</option>
              <option value="option2">Option 2</option>
            </ModelInput>
          </Col>
          <Col><button>Try it out</button></Col>
        </Row>
      </ModelForm>
    </div>

Version data entries

32 entries across 32 versions & 1 rubygems

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