Class DS.Errors
Extends: | Ember.Object |
---|---|
Uses: | Ember.Evented , | Ember.Enumerable
Defined in: | addon/-private/system/model/errors.js:14 |
Module: | ember-data |
errorsFor (attribute) Array
Module: | ember-data |
---|
Defined in addon/-private/system/model/errors.js:135
- attribute
- String
- returns
- Array
Returns errors for a given attribute
let user = store.createRecord('user', { username: 'tomster', email: 'invalidEmail' }); user.save().catch(function(){ user.get('errors').errorsFor('email'); // returns: // [{attribute: "email", message: "Doesn't look like a valid email."}] });
has (attribute) Boolean
Module: | ember-data |
---|
Defined in addon/-private/system/model/errors.js:405
- attribute
- String
- returns
- Boolean
- true if there some errors on given attribute
Checks if there is error messages for the given attribute.
app/routes/user/edit.js
import Route from '@ember/routing/route'; export default Route.extend({ actions: { save: function(user) { if (user.get('errors').has('email')) { return alert('Please update your email before attempting to save.'); } user.save(); } } });
© 2020 Yehuda Katz, Tom Dale and Ember.js contributors
Licensed under the MIT License.
https://api.emberjs.com/ember-data/2.18/classes/DS.Errors/methods