Ember-data isValid, isSaving and isError

I have a simple ember data model:

WZ.Exercise = DS.Model.extend
  name: DS.attr 'string'
  description: DS.attr 'string'
  group: DS.belongsTo 'WZ.Group'

I want to show the user a confirmation if a new record is saved or an error has occurred. The error may be that the object is invalid and a json error is returned, as shown below:

{"errors":{"description":["can't be blank"]}}

I see that each model has the isSaving property, isValid and the isError property.

Can someone tell me how I can use these properties to display the correct notifications to users?

+5
source share
2 answers

I can’t help you with the verification part, but if you want to display information to the user based on the state of the data, you can use this status in your view template as follows:

{{#if content.isNew }}
  <button {{ action save }} >Save</button>
{{/if}}
{{#if content.isSaving }}
  <i>Saving record...</i>
{{/if }}
{{#if content.isLoaded }}
  <b>Record created</b>
{{/if }}
{{#unless content.isValid }}
  <error>Error saving data</error>
{{/unless }}
+3
source

sly7_7 ( ObserverSaveOnce DS.Model), RESTadapter, .

: https://gist.github.com/3981832

( , ember)

+1

All Articles