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.

351 lines
14 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. /*====================================================================
  20. * Individual checkbox/radio examples
  21. *====================================================================*/
  22. // Using checkbox/radio groups will generally be easier and more flexible than
  23. // using individual checkbox and radio controls, but this shows that you can
  24. // certainly do so if you only need a single control, or if you want to control
  25. // exactly where each check/radio goes within your layout.
  26. var individual = [{
  27. bodyStyle: 'padding-right:5px;',
  28. items: {
  29. xtype: 'fieldset',
  30. title: 'Individual Checkboxes',
  31. autoHeight: true,
  32. defaultType: 'checkbox', // each item will be a checkbox
  33. items: [{
  34. xtype: 'textfield',
  35. name: 'txt-test1',
  36. fieldLabel: 'Alignment Test'
  37. }, {
  38. fieldLabel: 'Favorite Animals',
  39. boxLabel: 'Dog',
  40. name: 'fav-animal-dog'
  41. }, {
  42. fieldLabel: '',
  43. labelSeparator: '',
  44. boxLabel: 'Cat',
  45. name: 'fav-animal-cat'
  46. }, {
  47. checked: true,
  48. fieldLabel: '',
  49. labelSeparator: '',
  50. boxLabel: 'Monkey',
  51. name: 'fav-animal-monkey'
  52. }]
  53. }
  54. }, {
  55. bodyStyle: 'padding-left:5px;',
  56. items: {
  57. xtype: 'fieldset',
  58. title: 'Individual Radios',
  59. autoHeight: true,
  60. defaultType: 'radio', // each item will be a radio button
  61. items: [{
  62. xtype: 'textfield',
  63. name: 'txt-test2',
  64. fieldLabel: 'Alignment Test'
  65. }, {
  66. checked: true,
  67. fieldLabel: 'Favorite Color',
  68. boxLabel: 'Red',
  69. name: 'fav-color',
  70. inputValue: 'red'
  71. }, {
  72. fieldLabel: '',
  73. labelSeparator: '',
  74. boxLabel: 'Blue',
  75. name: 'fav-color',
  76. inputValue: 'blue'
  77. }, {
  78. fieldLabel: '',
  79. labelSeparator: '',
  80. boxLabel: 'Green',
  81. name: 'fav-color',
  82. inputValue: 'green'
  83. }]
  84. }
  85. }];
  86. /*====================================================================
  87. * CheckGroup example
  88. *====================================================================*/
  89. var checkGroup = {
  90. xtype: 'fieldset',
  91. title: 'Checkbox Groups (initially collapsed)',
  92. autoHeight: true,
  93. layout: 'form',
  94. collapsed: true, // initially collapse the group
  95. collapsible: true,
  96. items: [{
  97. xtype: 'textfield',
  98. name: 'txt-test3',
  99. fieldLabel: 'Alignment Test',
  100. anchor: '95%'
  101. },{
  102. // Use the default, automatic layout to distribute the controls evenly
  103. // across a single row
  104. xtype: 'checkboxgroup',
  105. fieldLabel: 'Auto Layout',
  106. items: [
  107. {boxLabel: 'Item 1', name: 'cb-auto-1'},
  108. {boxLabel: 'Item 2', name: 'cb-auto-2', checked: true},
  109. {boxLabel: 'Item 3', name: 'cb-auto-3'},
  110. {boxLabel: 'Item 4', name: 'cb-auto-4'},
  111. {boxLabel: 'Item 5', name: 'cb-auto-5'}
  112. ]
  113. },{
  114. xtype: 'checkboxgroup',
  115. fieldLabel: 'Single Column',
  116. itemCls: 'x-check-group-alt',
  117. // Put all controls in a single column with width 100%
  118. columns: 1,
  119. items: [
  120. {boxLabel: 'Item 1', name: 'cb-col-1'},
  121. {boxLabel: 'Item 2', name: 'cb-col-2', checked: true},
  122. {boxLabel: 'Item 3', name: 'cb-col-3'}
  123. ]
  124. },{
  125. xtype: 'checkboxgroup',
  126. fieldLabel: 'Multi-Column (horizontal)',
  127. // Distribute controls across 3 even columns, filling each row
  128. // from left to right before starting the next row
  129. columns: 3,
  130. items: [
  131. {boxLabel: 'Item 1', name: 'cb-horiz-1'},
  132. {boxLabel: 'Item 2', name: 'cb-horiz-2', checked: true},
  133. {boxLabel: 'Item 3', name: 'cb-horiz-3'},
  134. {boxLabel: 'Item 4', name: 'cb-horiz-4'},
  135. {boxLabel: 'Item 5', name: 'cb-horiz-5'}
  136. ]
  137. },{
  138. xtype: 'checkboxgroup',
  139. fieldLabel: 'Multi-Column (vertical)',
  140. itemCls: 'x-check-group-alt',
  141. // Distribute controls across 3 even columns, filling each column
  142. // from top to bottom before starting the next column
  143. columns: 3,
  144. vertical: true,
  145. items: [
  146. {boxLabel: 'Item 1', name: 'cb-vert-1'},
  147. {boxLabel: 'Item 2', name: 'cb-vert-2', checked: true},
  148. {boxLabel: 'Item 3', name: 'cb-vert-3'},
  149. {boxLabel: 'Item 4', name: 'cb-vert-4'},
  150. {boxLabel: 'Item 5', name: 'cb-vert-5'}
  151. ]
  152. },{
  153. xtype: 'checkboxgroup',
  154. fieldLabel: 'Multi-Column<br />(custom widths)',
  155. // Specify exact column widths (could also include float values for %)
  156. columns: [100, 100],
  157. vertical: true,
  158. items: [
  159. {boxLabel: 'Item 1', name: 'cb-custwidth', inputValue: 1},
  160. {boxLabel: 'Item 2', name: 'cb-custwidth', inputValue: 2, checked: true},
  161. {boxLabel: 'Item 3', name: 'cb-custwidth', inputValue: 3},
  162. {boxLabel: 'Item 4', name: 'cb-custwidth', inputValue: 4},
  163. {boxLabel: 'Item 5', name: 'cb-custwidth', inputValue: 5}
  164. ]
  165. },{
  166. xtype: 'checkboxgroup',
  167. itemCls: 'x-check-group-alt',
  168. fieldLabel: 'Custom Layout<br />(w/ validation)',
  169. allowBlank: false,
  170. anchor: '95%',
  171. items: [{
  172. // You can pass sub-item arrays along with width/columnWidth configs
  173. // ColumnLayout-style for complete layout control. In this example we
  174. // only want one item in the middle column, which would not be possible
  175. // using the columns config. We also want to make sure that our headings
  176. // end up at the top of each column as expected.
  177. columnWidth: '.25',
  178. items: [
  179. {xtype: 'label', text: 'Heading 1', cls:'x-form-check-group-label', anchor:'-15'},
  180. {boxLabel: 'Item 1', name: 'cb-cust-1'},
  181. {boxLabel: 'Item 2', name: 'cb-cust-2'}
  182. ]
  183. },{
  184. columnWidth: '.5',
  185. items: [
  186. {xtype: 'label', text: 'Heading 2', cls:'x-form-check-group-label', anchor:'-15'},
  187. {boxLabel: 'A long item just for fun', name: 'cb-cust-3'}
  188. ]
  189. },{
  190. columnWidth: '.25',
  191. items: [
  192. {xtype: 'label', text: 'Heading 3', cls:'x-form-check-group-label', anchor:'-15'},
  193. {boxLabel: 'Item 4', name: 'cb-cust-4'},
  194. {boxLabel: 'Item 5', name: 'cb-cust-5'}
  195. ]
  196. }]
  197. }]
  198. };
  199. /*====================================================================
  200. * RadioGroup examples
  201. *====================================================================*/
  202. // NOTE: These radio examples use the exact same options as the checkbox ones
  203. // above, so the comments will not be repeated. Please see comments above for
  204. // additional explanation on some config options.
  205. var radioGroup = {
  206. xtype: 'fieldset',
  207. title: 'Radio Groups',
  208. autoHeight: true,
  209. items: [{
  210. xtype: 'textfield',
  211. name: 'txt-test4',
  212. fieldLabel: 'Alignment Test',
  213. anchor: '95%'
  214. },{
  215. xtype: 'radiogroup',
  216. fieldLabel: 'Auto Layout',
  217. items: [
  218. {boxLabel: 'Item 1', name: 'rb-auto', inputValue: 1},
  219. {boxLabel: 'Item 2', name: 'rb-auto', inputValue: 2, checked: true},
  220. {boxLabel: 'Item 3', name: 'rb-auto', inputValue: 3},
  221. {boxLabel: 'Item 4', name: 'rb-auto', inputValue: 4},
  222. {boxLabel: 'Item 5', name: 'rb-auto', inputValue: 5}
  223. ]
  224. },{
  225. xtype: 'radiogroup',
  226. fieldLabel: 'Single Column',
  227. itemCls: 'x-check-group-alt',
  228. columns: 1,
  229. items: [
  230. {boxLabel: 'Item 1', name: 'rb-col', inputValue: 1},
  231. {boxLabel: 'Item 2', name: 'rb-col', inputValue: 2, checked: true},
  232. {boxLabel: 'Item 3', name: 'rb-col', inputValue: 3}
  233. ]
  234. },{
  235. xtype: 'radiogroup',
  236. fieldLabel: 'Multi-Column<br />(horiz. auto-width)',
  237. columns: 3,
  238. items: [
  239. {boxLabel: 'Item 1', name: 'rb-horiz', inputValue: 1},
  240. {boxLabel: 'Item 2', name: 'rb-horiz', inputValue: 2, checked: true},
  241. {boxLabel: 'Item 3', name: 'rb-horiz', inputValue: 3},
  242. {boxLabel: 'Item 4', name: 'rb-horiz', inputValue: 4},
  243. {boxLabel: 'Item 5', name: 'rb-horiz', inputValue: 5}
  244. ]
  245. },{
  246. xtype: 'radiogroup',
  247. fieldLabel: 'Multi-Column<br />(vert. auto-width)',
  248. itemCls: 'x-check-group-alt',
  249. columns: 3,
  250. vertical: true,
  251. items: [
  252. {boxLabel: 'Item 1', name: 'rb-vert', inputValue: 1},
  253. {boxLabel: 'Item 2', name: 'rb-vert', inputValue: 2, checked: true},
  254. {boxLabel: 'Item 3', name: 'rb-vert', inputValue: 3},
  255. {boxLabel: 'Item 4', name: 'rb-vert', inputValue: 4},
  256. {boxLabel: 'Item 5', name: 'rb-vert', inputValue: 5}
  257. ]
  258. },{
  259. xtype: 'radiogroup',
  260. fieldLabel: 'Multi-Column<br />(custom widths)',
  261. columns: [100, 100],
  262. vertical: true,
  263. items: [
  264. {boxLabel: 'Item 1', name: 'rb-custwidth', inputValue: 1},
  265. {boxLabel: 'Item 2', name: 'rb-custwidth', inputValue: 2, checked: true},
  266. {boxLabel: 'Item 3', name: 'rb-custwidth', inputValue: 3},
  267. {boxLabel: 'Item 4', name: 'rb-custwidth', inputValue: 4},
  268. {boxLabel: 'Item 5', name: 'rb-custwidth', inputValue: 5}
  269. ]
  270. },{
  271. xtype: 'radiogroup',
  272. itemCls: 'x-check-group-alt',
  273. fieldLabel: 'Custom Layout<br />(w/ validation)',
  274. allowBlank: false,
  275. anchor: '95%',
  276. items: [{
  277. columnWidth: '.25',
  278. items: [
  279. {xtype: 'label', text: 'Heading 1', cls:'x-form-check-group-label', anchor:'-15'},
  280. {boxLabel: 'Item 1', name: 'rb-cust', inputValue: 1},
  281. {boxLabel: 'Item 2', name: 'rb-cust', inputValue: 2}
  282. ]
  283. },{
  284. columnWidth: '.5',
  285. items: [
  286. {xtype: 'label', text: 'Heading 2', cls:'x-form-check-group-label', anchor:'-15'},
  287. {boxLabel: 'A long item just for fun', name: 'rb-cust', inputValue: 3}
  288. ]
  289. },{
  290. columnWidth: '.25',
  291. items: [
  292. {xtype: 'label', text: 'Heading 3', cls:'x-form-check-group-label', anchor:'-15'},
  293. {boxLabel: 'Item 4', name: 'rb-cust', inputValue: 4},
  294. {boxLabel: 'Item 5', name: 'rb-cust', inputValue: 5}
  295. ]
  296. }]
  297. }]
  298. };
  299. // combine all that into one huge form
  300. var fp = new Ext.FormPanel({
  301. title: 'Check/Radio Groups Example',
  302. frame: true,
  303. labelWidth: 110,
  304. width: 600,
  305. renderTo:'form-ct',
  306. bodyStyle: 'padding:0 10px 0;',
  307. items: [
  308. {
  309. layout: 'column',
  310. border: false,
  311. // defaults are applied to all child items unless otherwise specified by child item
  312. defaults: {
  313. columnWidth: '.5',
  314. border: false
  315. },
  316. items: individual
  317. },
  318. checkGroup,
  319. radioGroup
  320. ],
  321. buttons: [{
  322. text: 'Save',
  323. handler: function(){
  324. if(fp.getForm().isValid()){
  325. Ext.Msg.alert('Submitted Values', 'The following will be sent to the server: <br />'+
  326. fp.getForm().getValues(true).replace(/&/g,', '));
  327. }
  328. }
  329. },{
  330. text: 'Reset',
  331. handler: function(){
  332. fp.getForm().reset();
  333. }
  334. }]
  335. });
  336. });