Created
July 29, 2016 09:06
-
-
Save gustaff-weldon/307e6aeb2ba4d22be9eeeec9990a4913 to your computer and use it in GitHub Desktop.
Setting errors on nested model
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
document.save() | |
.then(() => { | |
... some succcess logic handler ... | |
}) | |
.catch((error) => { | |
// mark propertiesModel as invalid - pass errors from server | |
if (Ember.typeOf(error.errors) === 'array') { | |
let store, modelClass, serverErrors, propertiesServerErrors | |
store = this.get('store') | |
modelClass = store.modelFor('document') | |
serverErrors = store.serializerFor('document').extractErrors(store, modelClass, error, currentDocument.id) | |
propertiesServerErrors = extractPropertiesErrors(serverErrors) | |
let propertiesModelErrors = currentDocument.get('propertiesModel.errors') | |
for (let attributeName in propertiesServerErrors) { | |
if (propertiesServerErrors.hasOwnProperty(attributeName)) { | |
propertiesModelErrors.add(attributeName, propertiesServerErrors[attributeName]) | |
} | |
} | |
} | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment