3 * @class Ext.data.Errors
4 * @extends Ext.util.MixedCollection
6 * <p>Wraps a collection of validation error responses and provides convenient functions for
7 * accessing and errors for specific fields.</p>
9 * <p>Usually this class does not need to be instantiated directly - instances are instead created
10 * automatically when {@link Ext.data.Model#validate validate} on a model instance:</p>
13 //validate some existing model instance - in this case it returned 2 failures messages
14 var errors = myModel.validate();
16 errors.isValid(); //false
19 errors.getByField('name'); // [{field: 'name', error: 'must be present'}]
20 errors.getByField('title'); // [{field: 'title', error: 'is too short'}]
23 Ext.define('Ext.data.Errors', {
24 extend: 'Ext.util.MixedCollection',
27 * Returns true if there are no errors in the collection
31 return this.length === 0;
35 * Returns all of the errors for the given field
36 * @param {String} fieldName The field to get errors for
37 * @return {Array} All errors for the given field
39 getByField: function(fieldName) {
43 for (i = 0; i < this.length; i++) {
44 error = this.items[i];
46 if (error.field == fieldName) {