/ext-4.0.7/examples/form/adv-vtypes.js

https://bitbucket.org/srogerf/javascript · JavaScript · 135 lines · 97 code · 13 blank · 25 comment · 12 complexity · cf25ed414b011f48e63649cd73a9b219 MD5 · raw file

  1. /*
  2. This file is part of Ext JS 4
  3. Copyright (c) 2011 Sencha Inc
  4. Contact: http://www.sencha.com/contact
  5. GNU General Public License Usage
  6. This file may be used under the terms of the GNU General Public License version 3.0 as published by the Free Software Foundation and appearing in the file LICENSE included in the packaging of this file. Please review the following information to ensure the GNU General Public License version 3.0 requirements will be met: http://www.gnu.org/copyleft/gpl.html.
  7. If you are unsure which license is appropriate for your use, please contact the sales department at http://www.sencha.com/contact.
  8. */
  9. Ext.require([
  10. 'Ext.form.*'
  11. ]);
  12. Ext.onReady(function() {
  13. // Add the additional 'advanced' VTypes
  14. Ext.apply(Ext.form.field.VTypes, {
  15. daterange: function(val, field) {
  16. var date = field.parseDate(val);
  17. if (!date) {
  18. return false;
  19. }
  20. if (field.startDateField && (!this.dateRangeMax || (date.getTime() != this.dateRangeMax.getTime()))) {
  21. var start = field.up('form').down('#' + field.startDateField);
  22. start.setMaxValue(date);
  23. start.validate();
  24. this.dateRangeMax = date;
  25. }
  26. else if (field.endDateField && (!this.dateRangeMin || (date.getTime() != this.dateRangeMin.getTime()))) {
  27. var end = field.up('form').down('#' + field.endDateField);
  28. end.setMinValue(date);
  29. end.validate();
  30. this.dateRangeMin = date;
  31. }
  32. /*
  33. * Always return true since we're only using this vtype to set the
  34. * min/max allowed values (these are tested for after the vtype test)
  35. */
  36. return true;
  37. },
  38. daterangeText: 'Start date must be less than end date',
  39. password: function(val, field) {
  40. if (field.initialPassField) {
  41. var pwd = field.up('form').down('#' + field.initialPassField);
  42. return (val == pwd.getValue());
  43. }
  44. return true;
  45. },
  46. passwordText: 'Passwords do not match'
  47. });
  48. /*
  49. * ================ Date Range =======================
  50. */
  51. var dr = Ext.create('Ext.FormPanel', {
  52. renderTo: 'dr',
  53. frame: true,
  54. title: 'Date Range',
  55. bodyPadding: '5px 5px 0',
  56. width: 350,
  57. fieldDefaults: {
  58. labelWidth: 125,
  59. msgTarget: 'side',
  60. autoFitErrors: false
  61. },
  62. defaults: {
  63. width: 300
  64. },
  65. defaultType: 'datefield',
  66. items: [
  67. {
  68. fieldLabel: 'Start Date',
  69. name: 'startdt',
  70. id: 'startdt',
  71. vtype: 'daterange',
  72. endDateField: 'enddt' // id of the end date field
  73. },
  74. {
  75. fieldLabel: 'End Date',
  76. name: 'enddt',
  77. id: 'enddt',
  78. vtype: 'daterange',
  79. startDateField: 'startdt' // id of the start date field
  80. }
  81. ]
  82. });
  83. /*
  84. * ================ Password Verification =======================
  85. */
  86. var pwd = Ext.create('Ext.FormPanel', {
  87. renderTo: 'pw',
  88. frame: true,
  89. title: 'Password Verification',
  90. bodyPadding: '5px 5px 0',
  91. width: 350,
  92. fieldDefaults: {
  93. labelWidth: 125,
  94. msgTarget: 'side',
  95. autoFitErrors: false
  96. },
  97. defaults: {
  98. width: 300,
  99. inputType: 'password'
  100. },
  101. defaultType: 'textfield',
  102. items: [
  103. {
  104. fieldLabel: 'Password',
  105. name: 'pass',
  106. id: 'pass'
  107. },
  108. {
  109. fieldLabel: 'Confirm Password',
  110. name: 'pass-cfrm',
  111. vtype: 'password',
  112. initialPassField: 'pass' // id of the initial password field
  113. }
  114. ]
  115. });
  116. });