Upgrade to ExtJS 4.0.7 - Released 10/19/2011
[extjs.git] / docs / source / Text2.html
1 <!DOCTYPE html>
2 <html>
3 <head>
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; }
10   </style>
11   <script type="text/javascript">
12     function highlight() {
13       document.getElementById(location.hash.replace(/#/, "")).className = "highlight";
14     }
15   </script>
16 </head>
17 <body onload="prettyPrint(); highlight();">
18   <pre class="prettyprint lang-js"><span id='Ext-layout-component-field-Text'>/**
19 </span> * @private
20  * @class Ext.layout.component.field.Text
21  * @extends Ext.layout.component.field.Field
22  * Layout class for {@link Ext.form.field.Text} fields. Handles sizing the input field.
23  */
24 Ext.define('Ext.layout.component.field.Text', {
25     extend: 'Ext.layout.component.field.Field',
26     alias: 'layout.textfield',
27     requires: ['Ext.util.TextMetrics'],
28
29     type: 'textfield',
30
31
32 <span id='Ext-layout-component-field-Text-method-beforeLayout'>    /**
33 </span>     * Allow layout to proceed if the {@link Ext.form.field.Text#grow} config is enabled and the value has
34      * changed since the last layout.
35      */
36     beforeLayout: function(width, height) {
37         var me = this,
38             owner = me.owner,
39             lastValue = this.lastValue,
40             value = owner.getRawValue();
41         this.lastValue = value;
42         return me.callParent(arguments) || (owner.grow &amp;&amp; value !== lastValue);
43     },
44
45
46 <span id='Ext-layout-component-field-Text-method-sizeBodyContents'>    /**
47 </span>     * Size the field body contents given the total dimensions of the bodyEl, taking into account the optional
48      * {@link Ext.form.field.Text#grow} configurations.
49      * @param {Number} width The bodyEl width
50      * @param {Number} height The bodyEl height
51      */
52     sizeBodyContents: function(width, height) {
53         var size = this.adjustForGrow(width, height);
54         this.setElementSize(this.owner.inputEl, size[0], size[1]);
55     },
56
57
58 <span id='Ext-layout-component-field-Text-method-adjustForGrow'>    /**
59 </span>     * Given the target bodyEl dimensions, adjust them if necessary to return the correct final
60      * size based on the text field's {@link Ext.form.field.Text#grow grow config}.
61      * @param {Number} width The bodyEl width
62      * @param {Number} height The bodyEl height
63      * @return {Number[]} [inputElWidth, inputElHeight]
64      */
65     adjustForGrow: function(width, height) {
66         var me = this,
67             owner = me.owner,
68             inputEl, value, calcWidth,
69             result = [width, height];
70
71         if (owner.grow) {
72             inputEl = owner.inputEl;
73
74             // Find the width that contains the whole text value
75             value = (inputEl.dom.value || (owner.hasFocus ? '' : owner.emptyText) || '') + owner.growAppend;
76             calcWidth = inputEl.getTextWidth(value) + inputEl.getBorderWidth(&quot;lr&quot;) + inputEl.getPadding(&quot;lr&quot;);
77
78             // Constrain
79             result[0] = Ext.Number.constrain(calcWidth, owner.growMin,
80                     Math.max(owner.growMin, Math.min(owner.growMax, Ext.isNumber(width) ? width : Infinity)));
81         }
82
83         return result;
84     }
85
86 });
87 </pre>
88 </body>
89 </html>