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 display a confirmation message to the user if a new record has been saved or if an error has occurred. The error could be that the the object is invalid and an error json is returned like below:
{"errors":{"description":["can't be blank"]}}
I can see that each model comes with an isSaving, isValid property and an isError property.
Can anybody tell me how I can use these properties to display the correct notifications to the users?
I can't help you with the validations part, but if you want to display information to the user based on the state of the data you can use these status in your view template like so:
{{#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 }}
Additional to sly7_7's first link (adding the ObserverSaveOnce
function to DS.Model
), you could patch the RESTadapter
to catch the server-side error messages.
An example implementation you can find here: https://gist.github.com/3981832
(I did not paste the code here because I may update the gist for newer versions of ember-data)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With