You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

139 lines
4.3 KiB

2 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
  1. /*
  2. This file is part of Ext JS 3.4
  3. Copyright (c) 2011-2013 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
  7. published by the Free Software Foundation and appearing in the file LICENSE included in the
  8. packaging of this file.
  9. Please review the following information to ensure the GNU General Public License version 3.0
  10. requirements will be met: http://www.gnu.org/copyleft/gpl.html.
  11. If you are unsure which license is appropriate for your use, please contact the sales department
  12. at http://www.sencha.com/contact.
  13. Build date: 2013-04-03 15:07:25
  14. */
  15. Ext.onReady(function(){
  16. Ext.QuickTips.init();
  17. // turn on validation errors beside the field globally
  18. Ext.form.Field.prototype.msgTarget = 'side';
  19. var fs = new Ext.FormPanel({
  20. frame: true,
  21. title:'XML Form',
  22. labelAlign: 'right',
  23. labelWidth: 85,
  24. width:340,
  25. waitMsgTarget: true,
  26. // configure how to read the XML Data
  27. reader : new Ext.data.XmlReader({
  28. record : 'contact',
  29. success: '@success'
  30. }, [
  31. {name: 'first', mapping:'name/first'}, // custom mapping
  32. {name: 'last', mapping:'name/last'},
  33. 'company', 'email', 'state',
  34. {name: 'dob', type:'date', dateFormat:'m/d/Y'} // custom data types
  35. ]),
  36. // reusable eror reader class defined at the end of this file
  37. errorReader: new Ext.form.XmlErrorReader(),
  38. items: [
  39. new Ext.form.FieldSet({
  40. title: 'Contact Information',
  41. autoHeight: true,
  42. defaultType: 'textfield',
  43. items: [{
  44. fieldLabel: 'First Name',
  45. emptyText: 'First Name',
  46. name: 'first',
  47. width:190
  48. }, {
  49. fieldLabel: 'Last Name',
  50. emptyText: 'Last Name',
  51. name: 'last',
  52. width:190
  53. }, {
  54. fieldLabel: 'Company',
  55. name: 'company',
  56. width:190
  57. }, {
  58. fieldLabel: 'Email',
  59. name: 'email',
  60. vtype:'email',
  61. width:190
  62. },
  63. new Ext.form.ComboBox({
  64. fieldLabel: 'State',
  65. hiddenName:'state',
  66. store: new Ext.data.ArrayStore({
  67. fields: ['abbr', 'state'],
  68. data : Ext.exampledata.states // from states.js
  69. }),
  70. valueField:'abbr',
  71. displayField:'state',
  72. typeAhead: true,
  73. mode: 'local',
  74. triggerAction: 'all',
  75. emptyText:'Select a state...',
  76. selectOnFocus:true,
  77. width:190
  78. }),
  79. new Ext.form.DateField({
  80. fieldLabel: 'Date of Birth',
  81. name: 'dob',
  82. width:190,
  83. allowBlank:false
  84. })
  85. ]
  86. })
  87. ]
  88. });
  89. // simple button add
  90. fs.addButton('Load', function(){
  91. fs.getForm().load({url:'xml-form.xml', waitMsg:'Loading'});
  92. });
  93. // explicit add
  94. var submit = fs.addButton({
  95. text: 'Submit',
  96. disabled:true,
  97. handler: function(){
  98. fs.getForm().submit({url:'xml-errors.xml', waitMsg:'Saving Data...', submitEmptyText: false});
  99. }
  100. });
  101. fs.render('form-ct');
  102. fs.on({
  103. actioncomplete: function(form, action){
  104. if(action.type == 'load'){
  105. submit.enable();
  106. }
  107. }
  108. });
  109. });
  110. // A reusable error reader class for XML forms
  111. Ext.form.XmlErrorReader = function(){
  112. Ext.form.XmlErrorReader.superclass.constructor.call(this, {
  113. record : 'field',
  114. success: '@success'
  115. }, [
  116. 'id', 'msg'
  117. ]
  118. );
  119. };
  120. Ext.extend(Ext.form.XmlErrorReader, Ext.data.XmlReader);