xml-form.js 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. /*
  2. * Ext JS Library 2.0 Copyright(c) 2006-2007, Ext JS, LLC. licensing@extjs.com
  3. *
  4. * http://extjs.com/license
  5. */
  6. Ext.onReady(function() {
  7. Ext.QuickTips.init();
  8. // turn on validation errors beside the field globally
  9. Ext.form.Field.prototype.msgTarget = 'side';
  10. var fs = new Ext.FormPanel({
  11. frame : true,
  12. title : 'XML Form',
  13. labelAlign : 'right',
  14. labelWidth : 85,
  15. width : 340,
  16. waitMsgTarget : true,
  17. // configure how to read the XML Data
  18. reader : new Ext.data.XmlReader({
  19. record : 'contact',
  20. success : '@success'
  21. }, [{
  22. name : 'first',
  23. mapping : 'name/first'
  24. }, // custom mapping
  25. {
  26. name : 'last',
  27. mapping : 'name/last'
  28. }, 'company', 'email', 'state', {
  29. name : 'dob',
  30. type : 'date',
  31. dateFormat : 'm/d/Y'
  32. } // custom data types
  33. ]),
  34. // reusable eror reader class defined at the end of this file
  35. errorReader : new Ext.form.XmlErrorReader(),
  36. items : [new Ext.form.FieldSet({
  37. title : 'Contact Information',
  38. autoHeight : true,
  39. defaultType : 'textfield',
  40. items : [{
  41. fieldLabel : 'First Name',
  42. name : 'first',
  43. width : 190
  44. }, {
  45. fieldLabel : 'Last Name',
  46. name : 'last',
  47. width : 190
  48. }, {
  49. fieldLabel : 'Company',
  50. name : 'company',
  51. width : 190
  52. }, {
  53. fieldLabel : 'Email',
  54. name : 'email',
  55. vtype : 'email',
  56. width : 190
  57. },
  58. new Ext.form.ComboBox({
  59. fieldLabel : 'State',
  60. hiddenName : 'state',
  61. store : new Ext.data.SimpleStore(
  62. {
  63. fields : ['abbr',
  64. 'state'],
  65. data : Ext.exampledata.states
  66. // from states.js
  67. }),
  68. valueField : 'abbr',
  69. displayField : 'state',
  70. typeAhead : true,
  71. mode : 'local',
  72. triggerAction : 'all',
  73. emptyText : 'Select a state...',
  74. selectOnFocus : true,
  75. width : 190
  76. }),
  77. new Ext.form.DateField({
  78. fieldLabel : 'Date of Birth',
  79. name : 'dob',
  80. width : 190,
  81. allowBlank : false
  82. })]
  83. })]
  84. });
  85. // simple button add
  86. fs.addButton('Load', function() {
  87. fs.getForm().load({
  88. url : 'xml-form.xml',
  89. waitMsg : 'Loading'
  90. });
  91. });
  92. // explicit add
  93. var submit = fs.addButton({
  94. text : 'Submit',
  95. disabled : true,
  96. handler : function() {
  97. fs.getForm().submit({
  98. url : 'xml-errors.xml',
  99. waitMsg : 'Saving Data...'
  100. });
  101. }
  102. });
  103. fs.render('form-ct');
  104. fs.on({
  105. actioncomplete : function(form, action) {
  106. if (action.type == 'load') {
  107. submit.enable();
  108. }
  109. }
  110. });
  111. });
  112. // A reusable error reader class for XML forms
  113. Ext.form.XmlErrorReader = function() {
  114. Ext.form.XmlErrorReader.superclass.constructor.call(this, {
  115. record : 'field',
  116. success : '@success'
  117. }, ['id', 'msg']);
  118. };
  119. Ext.extend(Ext.form.XmlErrorReader, Ext.data.XmlReader);