combos.js 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  1. Ext.require([
  2. 'Ext.form.field.ComboBox',
  3. 'Ext.form.FieldSet',
  4. 'Ext.tip.QuickTipManager',
  5. 'Ext.data.*'
  6. ]);
  7. // Define the model for a State
  8. Ext.define('State', {
  9. extend: 'Ext.data.Model',
  10. fields: [
  11. {type: 'string', name: 'abbr'},
  12. {type: 'string', name: 'name'},
  13. {type: 'string', name: 'slogan'}
  14. ]
  15. });
  16. // The data for all states
  17. var states = [
  18. {"abbr":"AL","name":"Alabama","slogan":"The Heart of Dixie"},
  19. {"abbr":"AK","name":"Alaska","slogan":"The Land of the Midnight Sun"},
  20. {"abbr":"AZ","name":"Arizona","slogan":"The Grand Canyon State"},
  21. {"abbr":"AR","name":"Arkansas","slogan":"The Natural State"},
  22. {"abbr":"CA","name":"California","slogan":"The Golden State"},
  23. {"abbr":"CO","name":"Colorado","slogan":"The Mountain State"},
  24. {"abbr":"CT","name":"Connecticut","slogan":"The Constitution State"},
  25. {"abbr":"DE","name":"Delaware","slogan":"The First State"},
  26. {"abbr":"DC","name":"District of Columbia","slogan":"The Nation's Capital"},
  27. {"abbr":"FL","name":"Florida","slogan":"The Sunshine State"},
  28. {"abbr":"GA","name":"Georgia","slogan":"The Peach State"},
  29. {"abbr":"HI","name":"Hawaii","slogan":"The Aloha State"},
  30. {"abbr":"ID","name":"Idaho","slogan":"Famous Potatoes"},
  31. {"abbr":"IL","name":"Illinois","slogan":"The Prairie State"},
  32. {"abbr":"IN","name":"Indiana","slogan":"The Hospitality State"},
  33. {"abbr":"IA","name":"Iowa","slogan":"The Corn State"},
  34. {"abbr":"KS","name":"Kansas","slogan":"The Sunflower State"},
  35. {"abbr":"KY","name":"Kentucky","slogan":"The Bluegrass State"},
  36. {"abbr":"LA","name":"Louisiana","slogan":"The Bayou State"},
  37. {"abbr":"ME","name":"Maine","slogan":"The Pine Tree State"},
  38. {"abbr":"MD","name":"Maryland","slogan":"Chesapeake State"},
  39. {"abbr":"MA","name":"Massachusetts","slogan":"The Spirit of America"},
  40. {"abbr":"MI","name":"Michigan","slogan":"Great Lakes State"},
  41. {"abbr":"MN","name":"Minnesota","slogan":"North Star State"},
  42. {"abbr":"MS","name":"Mississippi","slogan":"Magnolia State"},
  43. {"abbr":"MO","name":"Missouri","slogan":"Show Me State"},
  44. {"abbr":"MT","name":"Montana","slogan":"Big Sky Country"},
  45. {"abbr":"NE","name":"Nebraska","slogan":"Beef State"},
  46. {"abbr":"NV","name":"Nevada","slogan":"Silver State"},
  47. {"abbr":"NH","name":"New Hampshire","slogan":"Granite State"},
  48. {"abbr":"NJ","name":"New Jersey","slogan":"Garden State"},
  49. {"abbr":"NM","name":"New Mexico","slogan":"Land of Enchantment"},
  50. {"abbr":"NY","name":"New York","slogan":"Empire State"},
  51. {"abbr":"NC","name":"North Carolina","slogan":"First in Freedom"},
  52. {"abbr":"ND","name":"North Dakota","slogan":"Peace Garden State"},
  53. {"abbr":"OH","name":"Ohio","slogan":"The Heart of it All"},
  54. {"abbr":"OK","name":"Oklahoma","slogan":"Oklahoma is OK"},
  55. {"abbr":"OR","name":"Oregon","slogan":"Pacific Wonderland"},
  56. {"abbr":"PA","name":"Pennsylvania","slogan":"Keystone State"},
  57. {"abbr":"RI","name":"Rhode Island","slogan":"Ocean State"},
  58. {"abbr":"SC","name":"South Carolina","slogan":"Nothing Could be Finer"},
  59. {"abbr":"SD","name":"South Dakota","slogan":"Great Faces, Great Places"},
  60. {"abbr":"TN","name":"Tennessee","slogan":"Volunteer State"},
  61. {"abbr":"TX","name":"Texas","slogan":"Lone Star State"},
  62. {"abbr":"UT","name":"Utah","slogan":"Salt Lake State"},
  63. {"abbr":"VT","name":"Vermont","slogan":"Green Mountain State"},
  64. {"abbr":"VA","name":"Virginia","slogan":"Mother of States"},
  65. {"abbr":"WA","name":"Washington","slogan":"Green Tree State"},
  66. {"abbr":"WV","name":"West Virginia","slogan":"Mountain State"},
  67. {"abbr":"WI","name":"Wisconsin","slogan":"America's Dairyland"},
  68. {"abbr":"WY","name":"Wyoming","slogan":"Like No Place on Earth"}
  69. ];
  70. function createStore() {
  71. // The data store holding the states; shared by each of the ComboBox examples below
  72. return Ext.create('Ext.data.Store', {
  73. autoDestroy: true,
  74. model: 'State',
  75. data: states
  76. });
  77. }
  78. Ext.onReady(function() {
  79. Ext.tip.QuickTipManager.init();
  80. // Simple ComboBox using the data store
  81. var simpleCombo = Ext.create('Ext.form.field.ComboBox', {
  82. fieldLabel: 'Select a single state',
  83. renderTo: 'simpleCombo',
  84. displayField: 'name',
  85. width: 320,
  86. labelWidth: 130,
  87. store: createStore(),
  88. queryMode: 'local',
  89. typeAhead: true
  90. });
  91. // ComboBox with a custom item template
  92. var customTplCombo = Ext.create('Ext.form.field.ComboBox', {
  93. fieldLabel: 'Select a single state',
  94. renderTo: 'customTplCombo',
  95. displayField: 'name',
  96. width: 320,
  97. labelWidth: 130,
  98. store: createStore(),
  99. queryMode: 'local',
  100. listConfig: {
  101. getInnerTpl: function() {
  102. return '<div data-qtip="{name}. {slogan}">{name} ({abbr})</div>';
  103. }
  104. }
  105. });
  106. // ComboBox with multiple selection enabled
  107. var multiCombo = Ext.create('Ext.form.field.ComboBox', {
  108. fieldLabel: 'Select multiple states',
  109. renderTo: 'multiSelectCombo',
  110. multiSelect: true,
  111. displayField: 'name',
  112. width: 320,
  113. labelWidth: 130,
  114. store: createStore(),
  115. queryMode: 'local'
  116. });
  117. // ComboBox transformed from HTML select
  118. var transformed = Ext.create('Ext.form.field.ComboBox', {
  119. typeAhead: true,
  120. transform: 'stateSelect',
  121. width: 135,
  122. forceSelection: true
  123. });
  124. ////// Collapsible code panels; ignore: /////
  125. Ext.select('pre.code').each(function(pre) {
  126. Ext.create('Ext.form.FieldSet', {
  127. contentEl: pre,
  128. renderTo: pre.parent(),
  129. title: 'View code for this example',
  130. collapsible: true,
  131. collapsed: true
  132. })
  133. });
  134. });