xml-form.js 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. Ext.require([
  2. 'Ext.form.*',
  3. 'Ext.data.*'
  4. ]);
  5. Ext.onReady(function(){
  6. Ext.define('example.contact', {
  7. extend: 'Ext.data.Model',
  8. fields: [
  9. {name: 'first', mapping: 'name > first'},
  10. {name: 'last', mapping: 'name > last'},
  11. 'company', 'email', 'state',
  12. {name: 'dob', type: 'date', dateFormat: 'm/d/Y'}
  13. ]
  14. });
  15. Ext.define('example.fielderror', {
  16. extend: 'Ext.data.Model',
  17. fields: ['id', 'msg']
  18. });
  19. var formPanel = Ext.create('Ext.form.Panel', {
  20. renderTo: 'form-ct',
  21. frame: true,
  22. title:'XML Form',
  23. width: 340,
  24. bodyPadding: 5,
  25. waitMsgTarget: true,
  26. fieldDefaults: {
  27. labelAlign: 'right',
  28. labelWidth: 85,
  29. msgTarget: 'side'
  30. },
  31. // configure how to read the XML data
  32. reader : Ext.create('Ext.data.reader.Xml', {
  33. model: 'example.contact',
  34. record : 'contact',
  35. successProperty: '@success'
  36. }),
  37. // configure how to read the XML errors
  38. errorReader: Ext.create('Ext.data.reader.Xml', {
  39. model: 'example.fielderror',
  40. record : 'field',
  41. successProperty: '@success'
  42. }),
  43. items: [{
  44. xtype: 'fieldset',
  45. title: 'Contact Information',
  46. defaultType: 'textfield',
  47. defaults: {
  48. width: 280
  49. },
  50. items: [{
  51. fieldLabel: 'First Name',
  52. emptyText: 'First Name',
  53. name: 'first'
  54. }, {
  55. fieldLabel: 'Last Name',
  56. emptyText: 'Last Name',
  57. name: 'last'
  58. }, {
  59. fieldLabel: 'Company',
  60. name: 'company'
  61. }, {
  62. fieldLabel: 'Email',
  63. name: 'email',
  64. vtype:'email'
  65. }, {
  66. xtype: 'combobox',
  67. fieldLabel: 'State',
  68. name: 'state',
  69. store: Ext.create('Ext.data.ArrayStore', {
  70. fields: ['abbr', 'state'],
  71. data : Ext.example.states // from states.js
  72. }),
  73. valueField: 'abbr',
  74. displayField: 'state',
  75. typeAhead: true,
  76. queryMode: 'local',
  77. emptyText: 'Select a state...'
  78. }, {
  79. xtype: 'datefield',
  80. fieldLabel: 'Date of Birth',
  81. name: 'dob',
  82. allowBlank: false,
  83. maxValue: new Date()
  84. }
  85. ]
  86. }],
  87. buttons: [{
  88. text: 'Load',
  89. handler: function(){
  90. formPanel.getForm().load({
  91. url: 'xml-form-data.xml',
  92. waitMsg: 'Loading...'
  93. });
  94. }
  95. }, {
  96. text: 'Submit',
  97. disabled: true,
  98. formBind: true,
  99. handler: function(){
  100. this.up('form').getForm().submit({
  101. url: 'xml-form-errors.xml',
  102. submitEmptyText: false,
  103. waitMsg: 'Saving Data...'
  104. });
  105. }
  106. }]
  107. });
  108. });