4 <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
5 <title>The source code</title>
6 <link href="../resources/prettify/prettify.css" type="text/css" rel="stylesheet" />
7 <script type="text/javascript" src="../resources/prettify/prettify.js"></script>
8 <style type="text/css">
9 .highlight { display: block; background-color: #ddd; }
11 <script type="text/javascript">
12 function highlight() {
13 document.getElementById(location.hash.replace(/#/, "")).className = "highlight";
17 <body onload="prettyPrint(); highlight();">
18 <pre class="prettyprint lang-js"><span id='Ext-form-FieldSet'>/**
19 </span> * @docauthor Jason Johnston <jason@sencha.com>
21 * A container for grouping sets of fields, rendered as a HTML `fieldset` element. The {@link #title}
22 * config will be rendered as the fieldset's `legend`.
24 * While FieldSets commonly contain simple groups of fields, they are general {@link Ext.container.Container Containers}
25 * and may therefore contain any type of components in their {@link #items}, including other nested containers.
26 * The default {@link #layout} for the FieldSet's items is `'anchor'`, but it can be configured to use any other
29 * FieldSets may also be collapsed if configured to do so; this can be done in two ways:
31 * 1. Set the {@link #collapsible} config to true; this will result in a collapse button being rendered next to
32 * the {@link #title legend title}, or:
33 * 2. Set the {@link #checkboxToggle} config to true; this is similar to using {@link #collapsible} but renders
34 * a {@link Ext.form.field.Checkbox checkbox} in place of the toggle button. The fieldset will be expanded when the
35 * checkbox is checked and collapsed when it is unchecked. The checkbox will also be included in the
36 * {@link Ext.form.Basic#submit form submit parameters} using the {@link #checkboxName} as its parameter name.
41 * Ext.create('Ext.form.Panel', {
42 * title: 'Simple Form with FieldSets',
43 * labelWidth: 75, // label settings here cascade unless overridden
44 * url: 'save-form.php',
46 * bodyStyle: 'padding:5px 5px 0',
48 * renderTo: Ext.getBody(),
49 * layout: 'column', // arrange fieldsets side by side
54 * // Fieldset in Column 1 - collapsible via toggle button
57 * title: 'Fieldset 1',
59 * defaultType: 'textfield',
60 * defaults: {anchor: '100%'},
63 * fieldLabel: 'Field 1',
66 * fieldLabel: 'Field 2',
70 * // Fieldset in Column 2 - collapsible via checkbox, collapsed by default, contains a panel
72 * title: 'Show Panel', // title or checkboxToggle creates fieldset header
74 * checkboxToggle: true,
75 * collapsed: true, // fieldset initially collapsed
80 * title: 'Panel inside a fieldset',
87 Ext.define('Ext.form.FieldSet', {
88 extend: 'Ext.container.Container',
89 alias: 'widget.fieldset',
90 uses: ['Ext.form.field.Checkbox', 'Ext.panel.Tool', 'Ext.layout.container.Anchor', 'Ext.layout.component.FieldSet'],
92 <span id='Ext-form-FieldSet-cfg-title'> /**
93 </span> * @cfg {String} title
94 * A title to be displayed in the fieldset's legend. May contain HTML markup.
97 <span id='Ext-form-FieldSet-cfg-checkboxToggle'> /**
98 </span> * @cfg {Boolean} [checkboxToggle=false]
99 * Set to true to render a checkbox into the fieldset frame just in front of the legend to expand/collapse the
100 * fieldset when the checkbox is toggled.. This checkbox will be included in form submits using
101 * the {@link #checkboxName}.
104 <span id='Ext-form-FieldSet-cfg-checkboxName'> /**
105 </span> * @cfg {String} checkboxName
106 * The name to assign to the fieldset's checkbox if {@link #checkboxToggle} = true
107 * (defaults to '[fieldset id]-checkbox').
110 <span id='Ext-form-FieldSet-cfg-collapsible'> /**
111 </span> * @cfg {Boolean} [collapsible=false]
112 * Set to true to make the fieldset collapsible and have the expand/collapse toggle button automatically rendered
113 * into the legend element, false to keep the fieldset statically sized with no collapse button.
114 * Another option is to configure {@link #checkboxToggle}. Use the {@link #collapsed} config to collapse the
115 * fieldset by default.
118 <span id='Ext-form-FieldSet-cfg-collapsed'> /**
119 </span> * @cfg {Boolean} collapsed
120 * Set to true to render the fieldset as collapsed by default. If {@link #checkboxToggle} is specified, the checkbox
121 * will also be unchecked by default.
125 <span id='Ext-form-FieldSet-property-legend'> /**
126 </span> * @property {Ext.Component} legend
127 * The component for the fieldset's legend. Will only be defined if the configuration requires a legend to be
128 * created, by setting the {@link #title} or {@link #checkboxToggle} options.
131 <span id='Ext-form-FieldSet-cfg-baseCls'> /**
132 </span> * @cfg {String} [baseCls='x-fieldset']
133 * The base CSS class applied to the fieldset.
135 baseCls: Ext.baseCSSPrefix + 'fieldset',
137 <span id='Ext-form-FieldSet-cfg-layout'> /**
138 </span> * @cfg {String} layout
139 * The {@link Ext.container.Container#layout} for the fieldset's immediate child items.
143 componentLayout: 'fieldset',
145 // No aria role necessary as fieldset has its own recognized semantics
148 renderTpl: ['<div id="{id}-body" class="{baseCls}-body"></div>'],
150 maskOnDisable: false,
152 getElConfig: function(){
153 return {tag: 'fieldset', id: this.id};
156 initComponent: function() {
158 baseCls = me.baseCls;
162 // Create the Legend component if needed
166 me.addChildEls('body');
169 me.addCls(baseCls + '-collapsed');
175 onRender: function(container, position) {
176 this.callParent(arguments);
177 // Make sure the legend is created and rendered
181 <span id='Ext-form-FieldSet-method-initLegend'> /**
183 * Initialize and render the legend component if necessary
185 initLegend: function() {
190 // Create the legend component if needed and it hasn't been already
191 if (!legend && (me.title || me.checkboxToggle || me.collapsible)) {
195 if (me.checkboxToggle) {
196 legendItems.push(me.createCheckboxCmp());
199 else if (me.collapsible) {
200 legendItems.push(me.createToggleCmp());
204 legendItems.push(me.createTitleCmp());
206 legend = me.legend = Ext.create('Ext.container.Container', {
207 baseCls: me.baseCls + '-header',
210 getElConfig: function(){
216 // Gecko3 will kick every <div> out of <legend> and mess up every thing.
217 // So here we change every <div> into <span>s. Therefore the following
218 // clearer is not needed and since div introduces a lot of subsequent
219 // problems, it is actually harmful.
222 cls: Ext.baseCSSPrefix + 'clear'
231 // Make sure legend is rendered if the fieldset is rendered
232 if (legend && !legend.rendered && me.rendered) {
233 me.legend.render(me.el, me.body); //insert before body element
237 <span id='Ext-form-FieldSet-method-createTitleCmp'> /**
238 </span> * Creates the legend title component. This is only called internally, but could be overridden in subclasses to
239 * customize the title component.
240 * @return Ext.Component
243 createTitleCmp: function() {
245 me.titleCmp = Ext.create('Ext.Component', {
247 getElConfig: function() {
249 tag: Ext.isGecko3 ? 'span' : 'div',
250 cls: me.titleCmp.cls,
254 cls: me.baseCls + '-header-text'
259 <span id='Ext-form-FieldSet-property-checkboxCmp'> /**
260 </span> * @property {Ext.form.field.Checkbox} checkboxCmp
261 * Refers to the {@link Ext.form.field.Checkbox} component that is added next to the title in the legend. Only
262 * populated if the fieldset is configured with {@link #checkboxToggle}:true.
265 <span id='Ext-form-FieldSet-method-createCheckboxCmp'> /**
266 </span> * Creates the checkbox component. This is only called internally, but could be overridden in subclasses to
267 * customize the checkbox's configuration or even return an entirely different component type.
268 * @return Ext.Component
271 createCheckboxCmp: function() {
273 suffix = '-checkbox';
275 me.checkboxCmp = Ext.create('Ext.form.field.Checkbox', {
276 getElConfig: function() {
278 tag: Ext.isGecko3 ? 'span' : 'div',
279 id: me.checkboxCmp.id,
280 cls: me.checkboxCmp.cls
283 name: me.checkboxName || me.id + suffix,
284 cls: me.baseCls + '-header' + suffix,
285 checked: !me.collapsed,
287 change: me.onCheckChange,
291 return me.checkboxCmp;
294 <span id='Ext-form-FieldSet-property-toggleCmp'> /**
295 </span> * @property {Ext.panel.Tool} toggleCmp
296 * Refers to the {@link Ext.panel.Tool} component that is added as the collapse/expand button next to the title in
297 * the legend. Only populated if the fieldset is configured with {@link #collapsible}:true.
300 <span id='Ext-form-FieldSet-method-createToggleCmp'> /**
301 </span> * Creates the toggle button component. This is only called internally, but could be overridden in subclasses to
302 * customize the toggle component.
303 * @return Ext.Component
306 createToggleCmp: function() {
308 me.toggleCmp = Ext.create('Ext.panel.Tool', {
309 getElConfig: function() {
311 tag: Ext.isGecko3 ? 'span' : 'div',
313 cls: me.toggleCmp.cls
323 <span id='Ext-form-FieldSet-method-setTitle'> /**
324 </span> * Sets the title of this fieldset
325 * @param {String} title The new title
326 * @return {Ext.form.FieldSet} this
328 setTitle: function(title) {
332 me.titleCmp.update(title);
336 getTargetEl : function() {
337 return this.body || this.frameBody || this.el;
340 getContentTarget: function() {
344 <span id='Ext-form-FieldSet-method-getRefItems'> /**
346 * Include the legend component in the items for ComponentQuery
348 getRefItems: function(deep) {
349 var refItems = this.callParent(arguments),
350 legend = this.legend;
352 // Prepend legend items to ensure correct order
354 refItems.unshift(legend);
356 refItems.unshift.apply(refItems, legend.getRefItems(true));
362 <span id='Ext-form-FieldSet-method-expand'> /**
363 </span> * Expands the fieldset.
364 * @return {Ext.form.FieldSet} this
367 return this.setExpanded(true);
370 <span id='Ext-form-FieldSet-method-collapse'> /**
371 </span> * Collapses the fieldset.
372 * @return {Ext.form.FieldSet} this
374 collapse : function() {
375 return this.setExpanded(false);
378 <span id='Ext-form-FieldSet-method-setExpanded'> /**
379 </span> * @private Collapse or expand the fieldset
381 setExpanded: function(expanded) {
383 checkboxCmp = me.checkboxCmp;
385 expanded = !!expanded;
388 checkboxCmp.setValue(expanded);
392 me.removeCls(me.baseCls + '-collapsed');
394 me.addCls(me.baseCls + '-collapsed');
396 me.collapsed = !expanded;
398 // ensure subitems will get rendered and layed out when expanding
399 me.getComponentLayout().childrenChanged = true;
401 me.doComponentLayout();
405 <span id='Ext-form-FieldSet-method-toggle'> /**
406 </span> * Toggle the fieldset's collapsed state to the opposite of what it is currently
409 this.setExpanded(!!this.collapsed);
412 <span id='Ext-form-FieldSet-method-onCheckChange'> /**
414 * Handle changes in the checkbox checked state
416 onCheckChange: function(cmp, checked) {
417 this.setExpanded(checked);
420 beforeDestroy : function() {
421 var legend = this.legend;