extjs radio样例集合

来源:互联网 发布:java获取自己程序路径 编辑:程序博客网 时间:2024/04/30 10:32
  1. Ext.onReady(function() { 
  2.     Ext.QuickTips.init(); 
  3.  
  4.     // turn on validation errors beside the field globally 
  5.     Ext.form.Field.prototype.msgTarget = 'side'
  6.  
  7.     var individual = [ { 
  8.         bodyStyle : 'padding-right:5px;'
  9.         items : { 
  10.             xtype : 'fieldset'
  11.             title : 'Individual Checkboxes'
  12.             autoHeight : true
  13.             defaultType : 'checkbox'// each item will be a checkbox 
  14.             items : [ { 
  15.                 xtype : 'textfield'
  16.                 name : 'txt-test1'
  17.                 fieldLabel : 'Alignment Test' 
  18.             }, { 
  19.                 fieldLabel : 'Favorite Animals'
  20.                 boxLabel : 'Dog'
  21.                 name : 'fav-animal-dog' 
  22.             }, { 
  23.                 fieldLabel : ''
  24.                 labelSeparator : ''
  25.                 boxLabel : 'Cat'
  26.                 name : 'fav-animal-cat' 
  27.             }, { 
  28.                 checked : true
  29.                 fieldLabel : ''
  30.                 labelSeparator : ''
  31.                 boxLabel : 'Monkey'
  32.                 name : 'fav-animal-monkey' 
  33.             } ] 
  34.         } 
  35.     }, { 
  36.         bodyStyle : 'padding-left:5px;'
  37.         items : { 
  38.             xtype : 'fieldset'
  39.             title : 'Individual Radios'
  40.             autoHeight : true
  41.             defaultType : 'radio'// each item will be a radio button 
  42.             items : [ { 
  43.                 xtype : 'textfield'
  44.                 name : 'txt-test2'
  45.                 fieldLabel : 'Alignment Test' 
  46.             }, { 
  47.                 checked : true
  48.                 fieldLabel : 'Favorite Color'
  49.                 boxLabel : 'Red'
  50.                 name : 'fav-color'
  51.                 inputValue : 'red' 
  52.             }, { 
  53.                 fieldLabel : ''
  54.                 labelSeparator : ''
  55.                 boxLabel : 'Blue'
  56.                 name : 'fav-color'
  57.                 inputValue : 'blue' 
  58.             }, { 
  59.                 fieldLabel : ''
  60.                 labelSeparator : ''
  61.                 boxLabel : 'Green'
  62.                 name : 'fav-color'
  63.                 inputValue : 'green' 
  64.             } ] 
  65.         } 
  66.     } ]; 
  67.  
  68.     /*==================================================================== 
  69.      * CheckGroup example 
  70.      *====================================================================*/ 
  71.     var checkGroup = { 
  72.         xtype : 'fieldset'
  73.         title : 'Checkbox Groups (initially collapsed)'
  74.         autoHeight : true
  75.         layout : 'form'
  76.         collapsed : true// initially collapse the group 
  77.         collapsible : true
  78.         items : [ { 
  79.             xtype : 'textfield'
  80.             name : 'txt-test3'
  81.             fieldLabel : 'Alignment Test'
  82.             anchor : '95%' 
  83.         }, { 
  84.             // Use the default, automatic layout to distribute the controls evenly 
  85.             // across a single row 
  86.             xtype : 'checkboxgroup'
  87.             fieldLabel : 'Auto Layout'
  88.             items : [ { 
  89.                 boxLabel : 'Item 1'
  90.                 name : 'cb-auto-1' 
  91.             }, { 
  92.                 boxLabel : 'Item 2'
  93.                 name : 'cb-auto-2'
  94.                 checked : true 
  95.             }, { 
  96.                 boxLabel : 'Item 3'
  97.                 name : 'cb-auto-3' 
  98.             }, { 
  99.                 boxLabel : 'Item 4'
  100.                 name : 'cb-auto-4' 
  101.             }, { 
  102.                 boxLabel : 'Item 5'
  103.                 name : 'cb-auto-5' 
  104.             } ] 
  105.         }, { 
  106.             xtype : 'checkboxgroup'
  107.             fieldLabel : 'Single Column'
  108.             itemCls : 'x-check-group-alt'
  109.             // Put all controls in a single column with width 100% 
  110.             columns : 1, 
  111.             items : [ { 
  112.                 boxLabel : 'Item 1'
  113.                 name : 'cb-col-1' 
  114.             }, { 
  115.                 boxLabel : 'Item 2'
  116.                 name : 'cb-col-2'
  117.                 checked : true 
  118.             }, { 
  119.                 boxLabel : 'Item 3'
  120.                 name : 'cb-col-3' 
  121.             } ] 
  122.         }, { 
  123.             xtype : 'checkboxgroup'
  124.             fieldLabel : 'Multi-Column (horizontal)'
  125.             // Distribute controls across 3 even columns, filling each row 
  126.             // from left to right before starting the next row 
  127.             columns : 3, 
  128.             items : [ { 
  129.                 boxLabel : 'Item 1'
  130.                 name : 'cb-horiz-1' 
  131.             }, { 
  132.                 boxLabel : 'Item 2'
  133.                 name : 'cb-horiz-2'
  134.                 checked : true 
  135.             }, { 
  136.                 boxLabel : 'Item 3'
  137.                 name : 'cb-horiz-3' 
  138.             }, { 
  139.                 boxLabel : 'Item 4'
  140.                 name : 'cb-horiz-4' 
  141.             }, { 
  142.                 boxLabel : 'Item 5'
  143.                 name : 'cb-horiz-5' 
  144.             } ] 
  145.         }, { 
  146.             xtype : 'checkboxgroup'
  147.             fieldLabel : 'Multi-Column (vertical)'
  148.             itemCls : 'x-check-group-alt'
  149.             // Distribute controls across 3 even columns, filling each column 
  150.             // from top to bottom before starting the next column 
  151.             columns : 3, 
  152.             vertical : true
  153.             items : [ { 
  154.                 boxLabel : 'Item 1'
  155.                 name : 'cb-vert-1' 
  156.             }, { 
  157.                 boxLabel : 'Item 2'
  158.                 name : 'cb-vert-2'
  159.                 checked : true 
  160.             }, { 
  161.                 boxLabel : 'Item 3'
  162.                 name : 'cb-vert-3' 
  163.             }, { 
  164.                 boxLabel : 'Item 4'
  165.                 name : 'cb-vert-4' 
  166.             }, { 
  167.                 boxLabel : 'Item 5'
  168.                 name : 'cb-vert-5' 
  169.             } ] 
  170.         }, { 
  171.             xtype : 'checkboxgroup'
  172.             fieldLabel : 'Multi-Column<br />(custom widths)'
  173.             // Specify exact column widths (could also include float values for %) 
  174.             columns : [ 100, 100 ], 
  175.             vertical : true
  176.             items : [ { 
  177.                 boxLabel : 'Item 1'
  178.                 name : 'cb-custwidth'
  179.                 inputValue : 1 
  180.             }, { 
  181.                 boxLabel : 'Item 2'
  182.                 name : 'cb-custwidth'
  183.                 inputValue : 2, 
  184.                 checked : true 
  185.             }, { 
  186.                 boxLabel : 'Item 3'
  187.                 name : 'cb-custwidth'
  188.                 inputValue : 3 
  189.             }, { 
  190.                 boxLabel : 'Item 4'
  191.                 name : 'cb-custwidth'
  192.                 inputValue : 4 
  193.             }, { 
  194.                 boxLabel : 'Item 5'
  195.                 name : 'cb-custwidth'
  196.                 inputValue : 5 
  197.             } ] 
  198.         }, { 
  199.             xtype : 'checkboxgroup'
  200.             itemCls : 'x-check-group-alt'
  201.             fieldLabel : 'Custom Layout<br />(w/ validation)'
  202.             allowBlank : false
  203.             anchor : '95%'
  204.             items : [ { 
  205.                 // You can pass sub-item arrays along with width/columnWidth configs  
  206.                 // ColumnLayout-style for complete layout control.  In this example we 
  207.                 // only want one item in the middle column, which would not be possible 
  208.                 // using the columns config.  We also want to make sure that our headings 
  209.                 // end up at the top of each column as expected. 
  210.                 columnWidth : '.25'
  211.                 items : [ { 
  212.                     xtype : 'label'
  213.                     text : 'Heading 1'
  214.                     cls : 'x-form-check-group-label'
  215.                     anchor : '-15' 
  216.                 }, { 
  217.                     boxLabel : 'Item 1'
  218.                     name : 'cb-cust-1' 
  219.                 }, { 
  220.                     boxLabel : 'Item 2'
  221.                     name : 'cb-cust-2' 
  222.                 } ] 
  223.             }, { 
  224.                 columnWidth : '.5'
  225.                 items : [ { 
  226.                     xtype : 'label'
  227.                     text : 'Heading 2'
  228.                     cls : 'x-form-check-group-label'
  229.                     anchor : '-15' 
  230.                 }, { 
  231.                     boxLabel : 'A long item just for fun'
  232.                     name : 'cb-cust-3' 
  233.                 } ] 
  234.             }, { 
  235.                 columnWidth : '.25'
  236.                 items : [ { 
  237.                     xtype : 'label'
  238.                     text : 'Heading 3'
  239.                     cls : 'x-form-check-group-label'
  240.                     anchor : '-15' 
  241.                 }, { 
  242.                     boxLabel : 'Item 4'
  243.                     name : 'cb-cust-4' 
  244.                 }, { 
  245.                     boxLabel : 'Item 5'
  246.                     name : 'cb-cust-5' 
  247.                 } ] 
  248.             } ] 
  249.         } ] 
  250.     }; 
  251.  
  252.     /*==================================================================== 
  253.      * RadioGroup examples 
  254.      *====================================================================*/ 
  255.  
  256.     var radioGroup = { 
  257.  
  258.         xtype : 'fieldset'
  259.         title : 'Radio Groups'
  260.         autoHeight : true
  261.         items : [ { 
  262.             xtype : 'textfield'
  263.             name : 'txt-test4'
  264.             fieldLabel : 'Alignment Test'
  265.             anchor : '95%' 
  266.         }, { 
  267.             xtype : 'radiogroup'
  268.             fieldLabel : 'Auto Layout'
  269.             items : [ { 
  270.                 boxLabel : 'Item 1'
  271.                 name : 'rb-auto'
  272.                 inputValue : 1 
  273.             }, { 
  274.                 boxLabel : 'Item 2'
  275.                 name : 'rb-auto'
  276.                 inputValue : 2, 
  277.                 checked : true 
  278.             }, { 
  279.                 boxLabel : 'Item 3'
  280.                 name : 'rb-auto'
  281.                 inputValue : 3 
  282.             }, { 
  283.                 boxLabel : 'Item 4'
  284.                 name : 'rb-auto'
  285.                 inputValue : 4 
  286.             }, { 
  287.                 boxLabel : 'Item 5'
  288.                 name : 'rb-auto'
  289.                 inputValue : 5 
  290.             } ] 
  291.         }, { 
  292.             xtype : 'radiogroup'
  293.             fieldLabel : 'Single Column'
  294.             itemCls : 'x-check-group-alt'
  295.             columns : 1, 
  296.             items : [ { 
  297.                 boxLabel : 'Item 1'
  298.                 name : 'rb-col'
  299.                 inputValue : 1 
  300.             }, { 
  301.                 boxLabel : 'Item 2'
  302.                 name : 'rb-col'
  303.                 inputValue : 2, 
  304.                 checked : true 
  305.             }, { 
  306.                 boxLabel : 'Item 3'
  307.                 name : 'rb-col'
  308.                 inputValue : 3 
  309.             } ] 
  310.         }, { 
  311.             xtype : 'radiogroup'
  312.             fieldLabel : 'Multi-Column<br />(horiz. auto-width)'
  313.             columns : 3, 
  314.             items : [ { 
  315.                 boxLabel : 'Item 1'
  316.                 name : 'rb-horiz'
  317.                 inputValue : 1 
  318.             }, { 
  319.                 boxLabel : 'Item 2'
  320.                 name : 'rb-horiz'
  321.                 inputValue : 2, 
  322.                 checked : true 
  323.             }, { 
  324.                 boxLabel : 'Item 3'
  325.                 name : 'rb-horiz'
  326.                 inputValue : 3 
  327.             }, { 
  328.                 boxLabel : 'Item 4'
  329.                 name : 'rb-horiz'
  330.                 inputValue : 4 
  331.             }, { 
  332.                 boxLabel : 'Item 5'
  333.                 name : 'rb-horiz'
  334.                 inputValue : 5 
  335.             } ] 
  336.         }, { 
  337.             xtype : 'radiogroup'
  338.             fieldLabel : 'Multi-Column<br />(vert. auto-width)'
  339.             itemCls : 'x-check-group-alt'
  340.             columns : 3, 
  341.             vertical : true
  342.             items : [ { 
  343.                 boxLabel : 'Item 1'
  344.                 name : 'rb-vert'
  345.                 inputValue : 1 
  346.             }, { 
  347.                 boxLabel : 'Item 2'
  348.                 name : 'rb-vert'
  349.                 inputValue : 2, 
  350.                 checked : true 
  351.             }, { 
  352.                 boxLabel : 'Item 3'
  353.                 name : 'rb-vert'
  354.                 inputValue : 3 
  355.             }, { 
  356.                 boxLabel : 'Item 4'
  357.                 name : 'rb-vert'
  358.                 inputValue : 4 
  359.             }, { 
  360.                 boxLabel : 'Item 5'
  361.                 name : 'rb-vert'
  362.                 inputValue : 5 
  363.             } ] 
  364.         }, { 
  365.             xtype : 'radiogroup'
  366.             fieldLabel : 'Multi-Column<br />(custom widths)'
  367.             columns : [ 100, 100 ], 
  368.             vertical : true
  369.             items : [ { 
  370.                 boxLabel : 'Item 1'
  371.                 name : 'rb-custwidth'
  372.                 inputValue : 1 
  373.             }, { 
  374.                 boxLabel : 'Item 2'
  375.                 name : 'rb-custwidth'
  376.                 inputValue : 2, 
  377.                 checked : true 
  378.             }, { 
  379.                 boxLabel : 'Item 3'
  380.                 name : 'rb-custwidth'
  381.                 inputValue : 3 
  382.             }, { 
  383.                 boxLabel : 'Item 4'
  384.                 name : 'rb-custwidth'
  385.                 inputValue : 4 
  386.             }, { 
  387.                 boxLabel : 'Item 5'
  388.                 name : 'rb-custwidth'
  389.                 inputValue : 5 
  390.             } ] 
  391.         }, { 
  392.             xtype : 'radiogroup'
  393.             itemCls : 'x-check-group-alt'
  394.             fieldLabel : 'Custom Layout<br />(w/ validation)'
  395.             allowBlank : false
  396.             anchor : '95%'
  397.             items : [ { 
  398.                 columnWidth : '.25'
  399.                 items : [ { 
  400.                     xtype : 'label'
  401.                     text : 'Heading 1'
  402.                     cls : 'x-form-check-group-label'
  403.                     anchor : '-15' 
  404.                 }, { 
  405.                     boxLabel : 'Item 1'
  406.                     name : 'rb-cust'
  407.                     inputValue : 1 
  408.                 }, { 
  409.                     boxLabel : 'Item 2'
  410.                     name : 'rb-cust'
  411.                     inputValue : 2 
  412.                 } ] 
  413.             }, { 
  414.                 columnWidth : '.5'
  415.                 items : [ { 
  416.                     xtype : 'label'
  417.                     text : 'Heading 2'
  418.                     cls : 'x-form-check-group-label'
  419.                     anchor : '-15' 
  420.                 }, { 
  421.                     boxLabel : 'A long item just for fun'
  422.                     name : 'rb-cust'
  423.                     inputValue : 3 
  424.                 } ] 
  425.             }, { 
  426.                 columnWidth : '.25'
  427.                 items : [ { 
  428.                     xtype : 'label'
  429.                     text : 'Heading 3'
  430.                     cls : 'x-form-check-group-label'
  431.                     anchor : '-15' 
  432.                 }, { 
  433.                     boxLabel : 'Item 4'
  434.                     name : 'rb-cust'
  435.                     inputValue : 4 
  436.                 }, { 
  437.                     boxLabel : 'Item 5'
  438.                     name : 'rb-cust'
  439.                     inputValue : 5 
  440.                 } ] 
  441.             } ] 
  442.         } ] 
  443.     }; 
  444.  
  445.     // combine all that into one huge form 
  446.     var fp = new Ext.FormPanel({ 
  447.         title : 'Check/Radio Groups Example'
  448.         frame : true
  449.         labelWidth : 110, 
  450.         width : 600, 
  451.         renderTo : 'container'
  452.         bodyStyle : 'padding:0 10px 0;'
  453.         items : [ { 
  454.             layout : 'column'
  455.             border : false
  456.             // defaults are applied to all child items unless otherwise specified by child item 
  457.             defaults : { 
  458.                 columnWidth : '.5'
  459.                 border : false 
  460.             }, 
  461.             items : individual 
  462.         }, checkGroup, radioGroup ], 
  463.         buttons : [ 
  464.                 { 
  465.                     text : 'Save'
  466.                     handler : function() { 
  467.                         if (fp.getForm().isValid()) { 
  468.                             Ext.Msg.alert('Submitted Values'
  469.                                     'The following will be sent to the server: <br />' 
  470.                                             + fp.getForm().getValues(true
  471.                                                     .replace(/&/g, ', ')); 
  472.                         } 
  473.                     } 
  474.                 }, { 
  475.                     text : 'Reset'
  476.                     handler : function() { 
  477.                         fp.getForm().reset(); 
  478.                     } 
  479.                 } ] 
  480.     }); 
  481. }); 

 

0 0
原创粉丝点击