1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377
|
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>The source code</title>
<link href="../resources/prettify/prettify.css" type="text/css" rel="stylesheet" />
<script type="text/javascript" src="../resources/prettify/prettify.js"></script>
</head>
<body onload="prettyPrint();">
<pre class="prettyprint lang-js">/*!
* Ext JS Library 3.4.0
* Copyright(c) 2006-2011 Sencha Inc.
* licensing@sencha.com
* http://www.sencha.com/license
*/
<div id="cls-Ext.layout.FormLayout"></div>/**
* @class Ext.layout.FormLayout
* @extends Ext.layout.AnchorLayout
* <p>This layout manager is specifically designed for rendering and managing child Components of
* {@link Ext.form.FormPanel forms}. It is responsible for rendering the labels of
* {@link Ext.form.Field Field}s.</p>
*
* <p>This layout manager is used when a Container is configured with the <tt>layout:'form'</tt>
* {@link Ext.Container#layout layout} config option, and should generally not need to be created directly
* via the new keyword. See <tt><b>{@link Ext.Container#layout}</b></tt> for additional details.</p>
*
* <p>In an application, it will usually be preferrable to use a {@link Ext.form.FormPanel FormPanel}
* (which is configured with FormLayout as its layout class by default) since it also provides built-in
* functionality for {@link Ext.form.BasicForm#doAction loading, validating and submitting} the form.</p>
*
* <p>A {@link Ext.Container Container} <i>using</i> the FormLayout layout manager (e.g.
* {@link Ext.form.FormPanel} or specifying <tt>layout:'form'</tt>) can also accept the following
* layout-specific config properties:<div class="mdetail-params"><ul>
* <li><b><tt>{@link Ext.form.FormPanel#hideLabels hideLabels}</tt></b></li>
* <li><b><tt>{@link Ext.form.FormPanel#labelAlign labelAlign}</tt></b></li>
* <li><b><tt>{@link Ext.form.FormPanel#labelPad labelPad}</tt></b></li>
* <li><b><tt>{@link Ext.form.FormPanel#labelSeparator labelSeparator}</tt></b></li>
* <li><b><tt>{@link Ext.form.FormPanel#labelWidth labelWidth}</tt></b></li>
* </ul></div></p>
*
* <p>Any Component (including Fields) managed by FormLayout accepts the following as a config option:
* <div class="mdetail-params"><ul>
* <li><b><tt>{@link Ext.Component#anchor anchor}</tt></b></li>
* </ul></div></p>
*
* <p>Any Component managed by FormLayout may be rendered as a form field (with an associated label) by
* configuring it with a non-null <b><tt>{@link Ext.Component#fieldLabel fieldLabel}</tt></b>. Components configured
* in this way may be configured with the following options which affect the way the FormLayout renders them:
* <div class="mdetail-params"><ul>
* <li><b><tt>{@link Ext.Component#clearCls clearCls}</tt></b></li>
* <li><b><tt>{@link Ext.Component#fieldLabel fieldLabel}</tt></b></li>
* <li><b><tt>{@link Ext.Component#hideLabel hideLabel}</tt></b></li>
* <li><b><tt>{@link Ext.Component#itemCls itemCls}</tt></b></li>
* <li><b><tt>{@link Ext.Component#labelSeparator labelSeparator}</tt></b></li>
* <li><b><tt>{@link Ext.Component#labelStyle labelStyle}</tt></b></li>
* </ul></div></p>
*
* <p>Example usage:</p>
* <pre><code>
// Required if showing validation messages
Ext.QuickTips.init();
// While you can create a basic Panel with layout:'form', practically
// you should usually use a FormPanel to also get its form functionality
// since it already creates a FormLayout internally.
var form = new Ext.form.FormPanel({
title: 'Form Layout',
bodyStyle: 'padding:15px',
width: 350,
defaultType: 'textfield',
defaults: {
// applied to each contained item
width: 230,
msgTarget: 'side'
},
items: [{
fieldLabel: 'First Name',
name: 'first',
allowBlank: false,
{@link Ext.Component#labelSeparator labelSeparator}: ':' // override labelSeparator layout config
},{
fieldLabel: 'Last Name',
name: 'last'
},{
fieldLabel: 'Email',
name: 'email',
vtype:'email'
}, {
xtype: 'textarea',
hideLabel: true, // override hideLabels layout config
name: 'msg',
anchor: '100% -53'
}
],
buttons: [
{text: 'Save'},
{text: 'Cancel'}
],
layoutConfig: {
{@link #labelSeparator}: '~' // superseded by assignment below
},
// config options applicable to container when layout='form':
hideLabels: false,
labelAlign: 'left', // or 'right' or 'top'
{@link Ext.form.FormPanel#labelSeparator labelSeparator}: '>>', // takes precedence over layoutConfig value
labelWidth: 65, // defaults to 100
labelPad: 8 // defaults to 5, must specify labelWidth to be honored
});
</code></pre>
*/
Ext.layout.FormLayout = Ext.extend(Ext.layout.AnchorLayout, {
<div id="cfg-Ext.layout.FormLayout-labelSeparator"></div>/**
* @cfg {String} labelSeparator
* See {@link Ext.form.FormPanel}.{@link Ext.form.FormPanel#labelSeparator labelSeparator}. Configuration
* of this property at the <b>container</b> level takes precedence.
*/
labelSeparator : ':',
<div id="prop-Ext.layout.FormLayout-labelStyle"></div>/**
* Read only. The CSS style specification string added to field labels in this layout if not
* otherwise {@link Ext.Component#labelStyle specified by each contained field}.
* @type String
* @property labelStyle
*/
<div id="cfg-Ext.layout.FormLayout-trackLabels"></div>/**
* @cfg {Boolean} trackLabels
* True to show/hide the field label when the field is hidden. Defaults to <tt>true</tt>.
*/
trackLabels: true,
type: 'form',
onRemove: function(c){
Ext.layout.FormLayout.superclass.onRemove.call(this, c);
if(this.trackLabels){
c.un('show', this.onFieldShow, this);
c.un('hide', this.onFieldHide, this);
}
// check for itemCt, since we may be removing a fieldset or something similar
var el = c.getPositionEl(),
ct = c.getItemCt && c.getItemCt();
if (c.rendered && ct) {
if (el && el.dom) {
el.insertAfter(ct);
}
Ext.destroy(ct);
Ext.destroyMembers(c, 'label', 'itemCt');
if (c.customItemCt) {
Ext.destroyMembers(c, 'getItemCt', 'customItemCt');
}
}
},
// private
setContainer : function(ct){
Ext.layout.FormLayout.superclass.setContainer.call(this, ct);
if(ct.labelAlign){
ct.addClass('x-form-label-'+ct.labelAlign);
}
if(ct.hideLabels){
Ext.apply(this, {
labelStyle: 'display:none',
elementStyle: 'padding-left:0;',
labelAdjust: 0
});
}else{
this.labelSeparator = Ext.isDefined(ct.labelSeparator) ? ct.labelSeparator : this.labelSeparator;
ct.labelWidth = ct.labelWidth || 100;
if(Ext.isNumber(ct.labelWidth)){
var pad = Ext.isNumber(ct.labelPad) ? ct.labelPad : 5;
Ext.apply(this, {
labelAdjust: ct.labelWidth + pad,
labelStyle: 'width:' + ct.labelWidth + 'px;',
elementStyle: 'padding-left:' + (ct.labelWidth + pad) + 'px'
});
}
if(ct.labelAlign == 'top'){
Ext.apply(this, {
labelStyle: 'width:auto;',
labelAdjust: 0,
elementStyle: 'padding-left:0;'
});
}
}
},
// private
isHide: function(c){
return c.hideLabel || this.container.hideLabels;
},
onFieldShow: function(c){
c.getItemCt().removeClass('x-hide-' + c.hideMode);
// Composite fields will need to layout after the container is made visible
if (c.isComposite) {
c.doLayout();
}
},
onFieldHide: function(c){
c.getItemCt().addClass('x-hide-' + c.hideMode);
},
//private
getLabelStyle: function(s){
var ls = '', items = [this.labelStyle, s];
for (var i = 0, len = items.length; i < len; ++i){
if (items[i]){
ls += items[i];
if (ls.substr(-1, 1) != ';'){
ls += ';';
}
}
}
return ls;
},
<div id="cfg-Ext.layout.FormLayout-fieldTpl"></div>/**
* @cfg {Ext.Template} fieldTpl
* A {@link Ext.Template#compile compile}d {@link Ext.Template} for rendering
* the fully wrapped, labeled and styled form Field. Defaults to:</p><pre><code>
new Ext.Template(
'<div class="x-form-item {itemCls}" tabIndex="-1">',
'<label for="{id}" style="{labelStyle}" class="x-form-item-label">{label}{labelSeparator}</label>',
'<div class="x-form-element" id="x-form-el-{id}" style="{elementStyle}">',
'</div><div class="{clearCls}"></div>',
'</div>'
);
</code></pre>
* <p>This may be specified to produce a different DOM structure when rendering form Fields.</p>
* <p>A description of the properties within the template follows:</p><div class="mdetail-params"><ul>
* <li><b><tt>itemCls</tt></b> : String<div class="sub-desc">The CSS class applied to the outermost div wrapper
* that contains this field label and field element (the default class is <tt>'x-form-item'</tt> and <tt>itemCls</tt>
* will be added to that). If supplied, <tt>itemCls</tt> at the field level will override the default <tt>itemCls</tt>
* supplied at the container level.</div></li>
* <li><b><tt>id</tt></b> : String<div class="sub-desc">The id of the Field</div></li>
* <li><b><tt>{@link #labelStyle}</tt></b> : String<div class="sub-desc">
* A CSS style specification string to add to the field label for this field (defaults to <tt>''</tt> or the
* {@link #labelStyle layout's value for <tt>labelStyle</tt>}).</div></li>
* <li><b><tt>label</tt></b> : String<div class="sub-desc">The text to display as the label for this
* field (defaults to <tt>''</tt>)</div></li>
* <li><b><tt>{@link #labelSeparator}</tt></b> : String<div class="sub-desc">The separator to display after
* the text of the label for this field (defaults to a colon <tt>':'</tt> or the
* {@link #labelSeparator layout's value for labelSeparator}). To hide the separator use empty string ''.</div></li>
* <li><b><tt>elementStyle</tt></b> : String<div class="sub-desc">The styles text for the input element's wrapper.</div></li>
* <li><b><tt>clearCls</tt></b> : String<div class="sub-desc">The CSS class to apply to the special clearing div
* rendered directly after each form field wrapper (defaults to <tt>'x-form-clear-left'</tt>)</div></li>
* </ul></div>
* <p>Also see <tt>{@link #getTemplateArgs}</tt></p>
*/
/**
* @private
*
*/
renderItem : function(c, position, target){
if(c && (c.isFormField || c.fieldLabel) && c.inputType != 'hidden'){
var args = this.getTemplateArgs(c);
if(Ext.isNumber(position)){
position = target.dom.childNodes[position] || null;
}
if(position){
c.itemCt = this.fieldTpl.insertBefore(position, args, true);
}else{
c.itemCt = this.fieldTpl.append(target, args, true);
}
if(!c.getItemCt){
// Non form fields don't have getItemCt, apply it here
// This will get cleaned up in onRemove
Ext.apply(c, {
getItemCt: function(){
return c.itemCt;
},
customItemCt: true
});
}
c.label = c.getItemCt().child('label.x-form-item-label');
if(!c.rendered){
c.render('x-form-el-' + c.id);
}else if(!this.isValidParent(c, target)){
Ext.fly('x-form-el-' + c.id).appendChild(c.getPositionEl());
}
if(this.trackLabels){
if(c.hidden){
this.onFieldHide(c);
}
c.on({
scope: this,
show: this.onFieldShow,
hide: this.onFieldHide
});
}
this.configureItem(c);
}else {
Ext.layout.FormLayout.superclass.renderItem.apply(this, arguments);
}
},
<div id="method-Ext.layout.FormLayout-getTemplateArgs"></div>/**
* <p>Provides template arguments for rendering the fully wrapped, labeled and styled form Field.</p>
* <p>This method returns an object hash containing properties used by the layout's {@link #fieldTpl}
* to create a correctly wrapped, labeled and styled form Field. This may be overriden to
* create custom layouts. The properties which must be returned are:</p><div class="mdetail-params"><ul>
* <li><b><tt>itemCls</tt></b> : String<div class="sub-desc">The CSS class applied to the outermost div wrapper
* that contains this field label and field element (the default class is <tt>'x-form-item'</tt> and <tt>itemCls</tt>
* will be added to that). If supplied, <tt>itemCls</tt> at the field level will override the default <tt>itemCls</tt>
* supplied at the container level.</div></li>
* <li><b><tt>id</tt></b> : String<div class="sub-desc">The id of the Field</div></li>
* <li><b><tt>{@link #labelStyle}</tt></b> : String<div class="sub-desc">
* A CSS style specification string to add to the field label for this field (defaults to <tt>''</tt> or the
* {@link #labelStyle layout's value for <tt>labelStyle</tt>}).</div></li>
* <li><b><tt>label</tt></b> : String<div class="sub-desc">The text to display as the label for this
* field (defaults to the field's configured fieldLabel property)</div></li>
* <li><b><tt>{@link #labelSeparator}</tt></b> : String<div class="sub-desc">The separator to display after
* the text of the label for this field (defaults to a colon <tt>':'</tt> or the
* {@link #labelSeparator layout's value for labelSeparator}). To hide the separator use empty string ''.</div></li>
* <li><b><tt>elementStyle</tt></b> : String<div class="sub-desc">The styles text for the input element's wrapper.</div></li>
* <li><b><tt>clearCls</tt></b> : String<div class="sub-desc">The CSS class to apply to the special clearing div
* rendered directly after each form field wrapper (defaults to <tt>'x-form-clear-left'</tt>)</div></li>
* </ul></div>
* @param (Ext.form.Field} field The {@link Ext.form.Field Field} being rendered.
* @return {Object} An object hash containing the properties required to render the Field.
*/
getTemplateArgs: function(field) {
var noLabelSep = !field.fieldLabel || field.hideLabel,
itemCls = (field.itemCls || this.container.itemCls || '') + (field.hideLabel ? ' x-hide-label' : '');
// IE9 quirks needs an extra, identifying class on wrappers of TextFields
if (Ext.isIE9 && Ext.isIEQuirks && field instanceof Ext.form.TextField) {
itemCls += ' x-input-wrapper';
}
return {
id : field.id,
label : field.fieldLabel,
itemCls : itemCls,
clearCls : field.clearCls || 'x-form-clear-left',
labelStyle : this.getLabelStyle(field.labelStyle),
elementStyle : this.elementStyle || '',
labelSeparator: noLabelSep ? '' : (Ext.isDefined(field.labelSeparator) ? field.labelSeparator : this.labelSeparator)
};
},
// private
adjustWidthAnchor: function(value, c){
if(c.label && !this.isHide(c) && (this.container.labelAlign != 'top')){
var adjust = Ext.isIE6 || (Ext.isIE && !Ext.isStrict);
return value - this.labelAdjust + (adjust ? -3 : 0);
}
return value;
},
adjustHeightAnchor : function(value, c){
if(c.label && !this.isHide(c) && (this.container.labelAlign == 'top')){
return value - c.label.getHeight();
}
return value;
},
// private
isValidParent : function(c, target){
return target && this.container.getEl().contains(c.getPositionEl());
}
<div id="prop-Ext.layout.FormLayout-activeItem"></div>/**
* @property activeItem
* @hide
*/
});
Ext.Container.LAYOUTS['form'] = Ext.layout.FormLayout;
</pre>
</body>
</html>
|