4 <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
5 <title>The source code</title>
6 <link href="../prettify/prettify.css" type="text/css" rel="stylesheet" />
7 <script type="text/javascript" src="../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-method-constructor'><span id='Ext-form-FieldSet'>/**
19 </span></span> * @class Ext.form.FieldSet
20 * @extends Ext.container.Container
22 * A container for grouping sets of fields, rendered as a HTML `fieldset` element. The {@link #title}
23 * config will be rendered as the fieldset's `legend`.
25 * While FieldSets commonly contain simple groups of fields, they are general {@link Ext.container.Container Containers}
26 * and may therefore contain any type of components in their {@link #items}, including other nested containers.
27 * The default {@link #layout} for the FieldSet's items is `'anchor'`, but it can be configured to use any other
30 * FieldSets may also be collapsed if configured to do so; this can be done in two ways:
32 * 1. Set the {@link #collapsible} config to true; this will result in a collapse button being rendered next to
33 * the {@link #title legend title}, or:
34 * 2. Set the {@link #checkboxToggle} config to true; this is similar to using {@link #collapsible} but renders
35 * a {@link Ext.form.field.Checkbox checkbox} in place of the toggle button. The fieldset will be expanded when the
36 * checkbox is checked and collapsed when it is unchecked. The checkbox will also be included in the
37 * {@link Ext.form.Basic#submit form submit parameters} using the {@link #checkboxName} as its parameter name.
39 * {@img Ext.form.FieldSet/Ext.form.FieldSet.png Ext.form.FieldSet component}
43 * Ext.create('Ext.form.Panel', {
44 * title: 'Simple Form with FieldSets',
45 * labelWidth: 75, // label settings here cascade unless overridden
46 * url: 'save-form.php',
48 * bodyStyle: 'padding:5px 5px 0',
50 * renderTo: Ext.getBody(),
51 * layout: 'column', // arrange fieldsets side by side
56 * // Fieldset in Column 1 - collapsible via toggle button
59 * title: 'Fieldset 1',
61 * defaultType: 'textfield',
62 * defaults: {anchor: '100%'},
65 * fieldLabel: 'Field 1',
68 * fieldLabel: 'Field 2',
72 * // Fieldset in Column 2 - collapsible via checkbox, collapsed by default, contains a panel
74 * title: 'Show Panel', // title or checkboxToggle creates fieldset header
76 * checkboxToggle: true,
77 * collapsed: true, // fieldset initially collapsed
82 * title: 'Panel inside a fieldset',
90 * Create a new FieldSet
91 * @param {Object} config Configuration options
93 * @docauthor Jason Johnston <jason@sencha.com>
95 Ext.define('Ext.form.FieldSet', {
96 extend: 'Ext.container.Container',
97 alias: 'widget.fieldset',
98 uses: ['Ext.form.field.Checkbox', 'Ext.panel.Tool', 'Ext.layout.container.Anchor', 'Ext.layout.component.FieldSet'],
100 <span id='Ext-form-FieldSet-cfg-title'> /**
101 </span> * @cfg {String} title
102 * A title to be displayed in the fieldset's legend. May contain HTML markup.
105 <span id='Ext-form-FieldSet-cfg-checkboxToggle'> /**
106 </span> * @cfg {Boolean} checkboxToggle
107 * Set to <tt>true</tt> to render a checkbox into the fieldset frame just
108 * in front of the legend to expand/collapse the fieldset when the checkbox is toggled. (defaults
109 * to <tt>false</tt>). This checkbox will be included in form submits using the {@link #checkboxName}.
112 <span id='Ext-form-FieldSet-cfg-checkboxName'> /**
113 </span> * @cfg {String} checkboxName
114 * The name to assign to the fieldset's checkbox if <tt>{@link #checkboxToggle} = true</tt>
115 * (defaults to <tt>'[fieldset id]-checkbox'</tt>).
118 <span id='Ext-form-FieldSet-cfg-collapsible'> /**
119 </span> * @cfg {Boolean} collapsible
120 * Set to <tt>true</tt> to make the fieldset collapsible and have the expand/collapse toggle button automatically
121 * rendered into the legend element, <tt>false</tt> to keep the fieldset statically sized with no collapse
122 * button (defaults to <tt>false</tt>). Another option is to configure <tt>{@link #checkboxToggle}</tt>.
123 * Use the {@link #collapsed} config to collapse the fieldset by default.
126 <span id='Ext-form-FieldSet-cfg-collapsed'> /**
127 </span> * @cfg {Boolean} collapsed
128 * Set to <tt>true</tt> to render the fieldset as collapsed by default. If {@link #checkboxToggle} is specified,
129 * the checkbox will also be unchecked by default.
133 <span id='Ext-form-FieldSet-property-legend'> /**
134 </span> * @property legend
135 * @type Ext.Component
136 * The component for the fieldset's legend. Will only be defined if the configuration requires a legend
137 * to be created, by setting the {@link #title} or {@link #checkboxToggle} options.
140 <span id='Ext-form-FieldSet-cfg-baseCls'> /**
141 </span> * @cfg {String} baseCls The base CSS class applied to the fieldset (defaults to <tt>'x-fieldset'</tt>).
143 baseCls: Ext.baseCSSPrefix + 'fieldset',
145 <span id='Ext-form-FieldSet-cfg-layout'> /**
146 </span> * @cfg {String} layout The {@link Ext.container.Container#layout} for the fieldset's immediate child items.
147 * Defaults to <tt>'anchor'</tt>.
151 componentLayout: 'fieldset',
153 // No aria role necessary as fieldset has its own recognized semantics
156 renderTpl: ['<div class="{baseCls}-body"></div>'],
158 maskOnDisable: false,
160 getElConfig: function(){
161 return {tag: 'fieldset', id: this.id};
164 initComponent: function() {
166 baseCls = me.baseCls;
170 // Create the Legend component if needed
173 // Add body el selector
174 Ext.applyIf(me.renderSelectors, {
175 body: '.' + baseCls + '-body'
179 me.addCls(baseCls + '-collapsed');
185 onRender: function(container, position) {
186 this.callParent(arguments);
187 // Make sure the legend is created and rendered
191 <span id='Ext-form-FieldSet-method-initLegend'> /**
193 * Initialize and render the legend component if necessary
195 initLegend: function() {
200 // Create the legend component if needed and it hasn't been already
201 if (!legend && (me.title || me.checkboxToggle || me.collapsible)) {
205 if (me.checkboxToggle) {
206 legendItems.push(me.createCheckboxCmp());
209 else if (me.collapsible) {
210 legendItems.push(me.createToggleCmp());
214 legendItems.push(me.createTitleCmp());
216 legend = me.legend = Ext.create('Ext.container.Container', {
217 baseCls: me.baseCls + '-header',
219 getElConfig: function(){
220 return {tag: 'legend', cls: this.baseCls};
226 // Make sure legend is rendered if the fieldset is rendered
227 if (legend && !legend.rendered && me.rendered) {
228 me.legend.render(me.el, me.body); //insert before body element
232 <span id='Ext-form-FieldSet-method-createTitleCmp'> /**
234 * Creates the legend title component. This is only called internally, but could be overridden in subclasses
235 * to customize the title component.
236 * @return Ext.Component
238 createTitleCmp: function() {
240 me.titleCmp = Ext.create('Ext.Component', {
242 cls: me.baseCls + '-header-text'
248 <span id='Ext-form-FieldSet-property-checkboxCmp'> /**
249 </span> * @property checkboxCmp
250 * @type Ext.form.field.Checkbox
251 * Refers to the {@link Ext.form.field.Checkbox} component that is added next to the title in the legend. Only
252 * populated if the fieldset is configured with <tt>{@link #checkboxToggle}:true</tt>.
255 <span id='Ext-form-FieldSet-method-createCheckboxCmp'> /**
257 * Creates the checkbox component. This is only called internally, but could be overridden in subclasses
258 * to customize the checkbox's configuration or even return an entirely different component type.
259 * @return Ext.Component
261 createCheckboxCmp: function() {
263 suffix = '-checkbox';
265 me.checkboxCmp = Ext.create('Ext.form.field.Checkbox', {
266 name: me.checkboxName || me.id + suffix,
267 cls: me.baseCls + '-header' + suffix,
268 checked: !me.collapsed,
270 change: me.onCheckChange,
274 return me.checkboxCmp;
277 <span id='Ext-form-FieldSet-property-toggleCmp'> /**
278 </span> * @property toggleCmp
279 * @type Ext.panel.Tool
280 * Refers to the {@link Ext.panel.Tool} component that is added as the collapse/expand button next
281 * to the title in the legend. Only populated if the fieldset is configured with <tt>{@link #collapsible}:true</tt>.
284 <span id='Ext-form-FieldSet-method-createToggleCmp'> /**
286 * Creates the toggle button component. This is only called internally, but could be overridden in
287 * subclasses to customize the toggle component.
288 * @return Ext.Component
290 createToggleCmp: function() {
292 me.toggleCmp = Ext.create('Ext.panel.Tool', {
300 <span id='Ext-form-FieldSet-method-setTitle'> /**
301 </span> * Sets the title of this fieldset
302 * @param {String} title The new title
303 * @return {Ext.form.FieldSet} this
305 setTitle: function(title) {
309 me.titleCmp.update(title);
313 getTargetEl : function() {
314 return this.body || this.frameBody || this.el;
317 getContentTarget: function() {
321 <span id='Ext-form-FieldSet-method-getRefItems'> /**
323 * Include the legend component in the items for ComponentQuery
325 getRefItems: function(deep) {
326 var refItems = this.callParent(arguments),
327 legend = this.legend;
329 // Prepend legend items to ensure correct order
331 refItems.unshift(legend);
333 refItems.unshift.apply(refItems, legend.getRefItems(true));
339 <span id='Ext-form-FieldSet-method-expand'> /**
340 </span> * Expands the fieldset.
341 * @return {Ext.form.FieldSet} this
344 return this.setExpanded(true);
347 <span id='Ext-form-FieldSet-method-collapse'> /**
348 </span> * Collapses the fieldset.
349 * @return {Ext.form.FieldSet} this
351 collapse : function() {
352 return this.setExpanded(false);
355 <span id='Ext-form-FieldSet-method-setExpanded'> /**
356 </span> * @private Collapse or expand the fieldset
358 setExpanded: function(expanded) {
360 checkboxCmp = me.checkboxCmp;
362 expanded = !!expanded;
365 checkboxCmp.setValue(expanded);
369 me.removeCls(me.baseCls + '-collapsed');
371 me.addCls(me.baseCls + '-collapsed');
373 me.collapsed = !expanded;
375 // ensure subitems will get rendered and layed out when expanding
376 me.getComponentLayout().childrenChanged = true;
378 me.doComponentLayout();
382 <span id='Ext-form-FieldSet-method-toggle'> /**
383 </span> * Toggle the fieldset's collapsed state to the opposite of what it is currently
386 this.setExpanded(!!this.collapsed);
389 <span id='Ext-form-FieldSet-method-onCheckChange'> /**
390 </span> * @private Handle changes in the checkbox checked state
392 onCheckChange: function(cmp, checked) {
393 this.setExpanded(checked);
396 beforeDestroy : function() {
397 var legend = this.legend;