Errors.html 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  5. <title>The source code</title>
  6. <link href="../resources/prettify/prettify.css" type="text/css" rel="stylesheet" />
  7. <script type="text/javascript" src="../resources/prettify/prettify.js"></script>
  8. <style type="text/css">
  9. .highlight { display: block; background-color: #ddd; }
  10. </style>
  11. <script type="text/javascript">
  12. function highlight() {
  13. document.getElementById(location.hash.replace(/#/, "")).className = "highlight";
  14. }
  15. </script>
  16. </head>
  17. <body onload="prettyPrint(); highlight();">
  18. <pre class="prettyprint lang-js"><span id='Ext-data-Errors'>/**
  19. </span> * @author Ed Spencer
  20. * @class Ext.data.Errors
  21. *
  22. * &lt;p&gt;Wraps a collection of validation error responses and provides convenient functions for
  23. * accessing and errors for specific fields.&lt;/p&gt;
  24. *
  25. * &lt;p&gt;Usually this class does not need to be instantiated directly - instances are instead created
  26. * automatically when {@link Ext.data.Model#validate validate} on a model instance:&lt;/p&gt;
  27. *
  28. &lt;pre&gt;&lt;code&gt;
  29. //validate some existing model instance - in this case it returned 2 failures messages
  30. var errors = myModel.validate();
  31. errors.isValid(); //false
  32. errors.length; //2
  33. errors.getByField('name'); // [{field: 'name', message: 'must be present'}]
  34. errors.getByField('title'); // [{field: 'title', message: 'is too short'}]
  35. &lt;/code&gt;&lt;/pre&gt;
  36. */
  37. Ext.define('Ext.data.Errors', {
  38. extend: 'Ext.util.MixedCollection',
  39. <span id='Ext-data-Errors-method-isValid'> /**
  40. </span> * Returns true if there are no errors in the collection
  41. * @return {Boolean}
  42. */
  43. isValid: function() {
  44. return this.length === 0;
  45. },
  46. <span id='Ext-data-Errors-method-getByField'> /**
  47. </span> * Returns all of the errors for the given field
  48. * @param {String} fieldName The field to get errors for
  49. * @return {Object[]} All errors for the given field
  50. */
  51. getByField: function(fieldName) {
  52. var errors = [],
  53. error, field, i;
  54. for (i = 0; i &lt; this.length; i++) {
  55. error = this.items[i];
  56. if (error.field == fieldName) {
  57. errors.push(error);
  58. }
  59. }
  60. return errors;
  61. }
  62. });
  63. </pre>
  64. </body>
  65. </html>