fieldcontainer.js 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228
  1. Ext.require([
  2. 'Ext.form.*',
  3. 'Ext.data.*',
  4. 'Ext.tip.QuickTipManager'
  5. ]);
  6. Ext.onReady(function() {
  7. Ext.QuickTips.init();
  8. Ext.define('Employee', {
  9. extend: 'Ext.data.Model',
  10. fields: [
  11. {name: 'email', type: 'string'},
  12. {name: 'title', type: 'string'},
  13. {name: 'firstName', type: 'string'},
  14. {name: 'lastName', type: 'string'},
  15. {name: 'phone-1', type: 'string'},
  16. {name: 'phone-2', type: 'string'},
  17. {name: 'phone-3', type: 'string'},
  18. {name: 'hours', type: 'number'},
  19. {name: 'minutes', type: 'number'},
  20. {name: 'startDate', type: 'date'},
  21. {name: 'endDate', type: 'date'}
  22. ]
  23. });
  24. var form = Ext.create('Ext.form.Panel', {
  25. renderTo: 'docbody',
  26. title : 'FieldContainers',
  27. autoHeight: true,
  28. width : 600,
  29. bodyPadding: 10,
  30. defaults: {
  31. anchor: '100%',
  32. labelWidth: 100
  33. },
  34. items : [
  35. {
  36. xtype : 'textfield',
  37. name : 'email',
  38. fieldLabel: 'Email Address',
  39. vtype: 'email',
  40. msgTarget: 'side',
  41. allowBlank: false
  42. },
  43. {
  44. xtype: 'fieldcontainer',
  45. fieldLabel: 'Date Range',
  46. combineErrors: true,
  47. msgTarget : 'side',
  48. layout: 'hbox',
  49. defaults: {
  50. flex: 1,
  51. hideLabel: true
  52. },
  53. items: [
  54. {
  55. xtype : 'datefield',
  56. name : 'startDate',
  57. fieldLabel: 'Start',
  58. margin: '0 5 0 0',
  59. allowBlank: false
  60. },
  61. {
  62. xtype : 'datefield',
  63. name : 'endDate',
  64. fieldLabel: 'End',
  65. allowBlank: false
  66. }
  67. ]
  68. },
  69. {
  70. xtype: 'fieldset',
  71. title: 'Details',
  72. collapsible: true,
  73. defaults: {
  74. labelWidth: 89,
  75. anchor: '100%',
  76. layout: {
  77. type: 'hbox',
  78. defaultMargins: {top: 0, right: 5, bottom: 0, left: 0}
  79. }
  80. },
  81. items: [
  82. {
  83. xtype: 'fieldcontainer',
  84. fieldLabel: 'Phone',
  85. combineErrors: true,
  86. msgTarget: 'under',
  87. defaults: {
  88. hideLabel: true
  89. },
  90. items: [
  91. {xtype: 'displayfield', value: '('},
  92. {xtype: 'textfield', fieldLabel: 'Phone 1', name: 'phone-1', width: 29, allowBlank: false},
  93. {xtype: 'displayfield', value: ')'},
  94. {xtype: 'textfield', fieldLabel: 'Phone 2', name: 'phone-2', width: 29, allowBlank: false, margins: '0 5 0 0'},
  95. {xtype: 'displayfield', value: '-'},
  96. {xtype: 'textfield', fieldLabel: 'Phone 3', name: 'phone-3', width: 48, allowBlank: false}
  97. ]
  98. },
  99. {
  100. xtype: 'fieldcontainer',
  101. fieldLabel: 'Time worked',
  102. combineErrors: false,
  103. defaults: {
  104. hideLabel: true
  105. },
  106. items: [
  107. {
  108. name : 'hours',
  109. xtype: 'numberfield',
  110. width: 48,
  111. allowBlank: false
  112. },
  113. {
  114. xtype: 'displayfield',
  115. value: 'hours'
  116. },
  117. {
  118. name : 'minutes',
  119. xtype: 'numberfield',
  120. width: 48,
  121. allowBlank: false
  122. },
  123. {
  124. xtype: 'displayfield',
  125. value: 'mins'
  126. }
  127. ]
  128. },
  129. {
  130. xtype : 'fieldcontainer',
  131. combineErrors: true,
  132. msgTarget: 'side',
  133. fieldLabel: 'Full Name',
  134. defaults: {
  135. hideLabel: true
  136. },
  137. items : [
  138. {
  139. //the width of this field in the HBox layout is set directly
  140. //the other 2 items are given flex: 1, so will share the rest of the space
  141. width: 50,
  142. xtype: 'combo',
  143. mode: 'local',
  144. value: 'mrs',
  145. triggerAction: 'all',
  146. forceSelection: true,
  147. editable: false,
  148. fieldLabel: 'Title',
  149. name: 'title',
  150. displayField: 'name',
  151. valueField: 'value',
  152. queryMode: 'local',
  153. store: Ext.create('Ext.data.Store', {
  154. fields : ['name', 'value'],
  155. data : [
  156. {name : 'Mr', value: 'mr'},
  157. {name : 'Mrs', value: 'mrs'},
  158. {name : 'Miss', value: 'miss'}
  159. ]
  160. })
  161. },
  162. {
  163. xtype: 'textfield',
  164. flex : 1,
  165. name : 'firstName',
  166. fieldLabel: 'First',
  167. allowBlank: false
  168. },
  169. {
  170. xtype: 'textfield',
  171. flex : 1,
  172. name : 'lastName',
  173. fieldLabel: 'Last',
  174. allowBlank: false,
  175. margins: '0'
  176. }
  177. ]
  178. }
  179. ]
  180. }
  181. ],
  182. buttons: [
  183. {
  184. text : 'Load test data',
  185. handler: function() {
  186. this.up('form').getForm().loadRecord(Ext.create('Employee', {
  187. 'email' : 'abe@sencha.com',
  188. 'title' : 'mr',
  189. 'firstName': 'Abraham',
  190. 'lastName' : 'Elias',
  191. 'startDate': '01/10/2003',
  192. 'endDate' : '12/11/2009',
  193. 'phone-1' : '555',
  194. 'phone-2' : '123',
  195. 'phone-3' : '4567',
  196. 'hours' : 7,
  197. 'minutes' : 15
  198. }));
  199. }
  200. },
  201. {
  202. text : 'Save',
  203. handler: function() {
  204. var form = this.up('form').getForm(),
  205. s = '';
  206. if (form.isValid()) {
  207. Ext.iterate(form.getValues(), function(key, value) {
  208. s += Ext.util.Format.format("{0} = {1}<br />", key, value);
  209. }, this);
  210. Ext.Msg.alert('Form Values', s);
  211. }
  212. }
  213. },
  214. {
  215. text : 'Reset',
  216. handler: function() {
  217. this.up('form').getForm().reset();
  218. }
  219. }
  220. ]
  221. });
  222. });