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-field-TextArea'>/**
19 </span> * @docauthor Robert Dougan <rob@sencha.com>
21 * This class creates a multiline text field, which can be used as a direct replacement for traditional
22 * textarea fields. In addition, it supports automatically {@link #grow growing} the height of the textarea to
25 * All of the configuration options from {@link Ext.form.field.Text} can be used on TextArea.
30 * Ext.create('Ext.form.FormPanel', {
31 * title : 'Sample TextArea',
34 * renderTo : Ext.getBody(),
36 * xtype : 'textareafield',
39 * fieldLabel: 'Message',
44 * Some other useful configuration options when using {@link #grow} are {@link #growMin} and {@link #growMax}.
45 * These allow you to set the minimum and maximum grow heights for the textarea.
47 Ext.define('Ext.form.field.TextArea', {
48 extend:'Ext.form.field.Text',
49 alias: ['widget.textareafield', 'widget.textarea'],
50 alternateClassName: 'Ext.form.TextArea',
51 requires: ['Ext.XTemplate', 'Ext.layout.component.field.TextArea'],
54 '<textarea id="{id}" ',
55 '<tpl if="name">name="{name}" </tpl>',
56 '<tpl if="rows">rows="{rows}" </tpl>',
57 '<tpl if="cols">cols="{cols}" </tpl>',
58 '<tpl if="tabIdx">tabIndex="{tabIdx}" </tpl>',
59 'class="{fieldCls} {typeCls}" ',
60 'autocomplete="off">',
68 <span id='Ext-form-field-TextArea-cfg-growMin'> /**
69 </span> * @cfg {Number} growMin
70 * The minimum height to allow when {@link #grow}=true
74 <span id='Ext-form-field-TextArea-cfg-growMax'> /**
75 </span> * @cfg {Number} growMax
76 * The maximum height to allow when {@link #grow}=true
80 <span id='Ext-form-field-TextArea-cfg-growAppend'> /**
81 </span> * @cfg {String} growAppend
82 * A string that will be appended to the field's current value for the purposes of calculating the target field
83 * size. Only used when the {@link #grow} config is true. Defaults to a newline for TextArea to ensure there is
84 * always a space below the current line.
88 <span id='Ext-form-field-TextArea-cfg-cols'> /**
89 </span> * @cfg {Number} cols
90 * An initial value for the 'cols' attribute on the textarea element. This is only used if the component has no
91 * configured {@link #width} and is not given a width by its container's layout.
95 <span id='Ext-form-field-TextArea-cfg-cols'> /**
96 </span> * @cfg {Number} cols
97 * An initial value for the 'cols' attribute on the textarea element. This is only used if the component has no
98 * configured {@link #width} and is not given a width by its container's layout.
102 <span id='Ext-form-field-TextArea-cfg-enterIsSpecial'> /**
103 </span> * @cfg {Boolean} enterIsSpecial
104 * True if you want the enter key to be classed as a special key. Special keys are generally navigation keys
105 * (arrows, space, enter). Setting the config property to true would mean that you could not insert returns into the
108 enterIsSpecial: false,
110 <span id='Ext-form-field-TextArea-cfg-preventScrollbars'> /**
111 </span> * @cfg {Boolean} preventScrollbars
112 * true to prevent scrollbars from appearing regardless of how much text is in the field. This option is only
113 * relevant when {@link #grow} is true. Equivalent to setting overflow: hidden.
115 preventScrollbars: false,
118 componentLayout: 'textareafield',
121 onRender: function(ct, position) {
123 Ext.applyIf(me.subTplData, {
128 me.callParent(arguments);
132 afterRender: function(){
135 me.callParent(arguments);
138 if (me.preventScrollbars) {
139 me.inputEl.setStyle('overflow', 'hidden');
141 me.inputEl.setHeight(me.growMin);
146 fireKey: function(e) {
147 if (e.isSpecialKey() && (this.enterIsSpecial || (e.getKey() !== e.ENTER || e.hasModifier()))) {
148 this.fireEvent('specialkey', this, e);
152 <span id='Ext-form-field-TextArea-method-autoSize'> /**
153 </span> * Automatically grows the field to accomodate the height of the text up to the maximum field height allowed. This
154 * only takes effect if {@link #grow} = true, and fires the {@link #autosize} event if the height changes.
156 autoSize: function() {
160 if (me.grow && me.rendered) {
161 me.doComponentLayout();
162 height = me.inputEl.getHeight();
163 if (height !== me.lastInputHeight) {
164 me.fireEvent('autosize', height);
165 me.lastInputHeight = height;
171 initAria: function() {
172 this.callParent(arguments);
173 this.getActionEl().dom.setAttribute('aria-multiline', true);
176 <span id='Ext-form-field-TextArea-method-getBodyNaturalWidth'> /**
177 </span> * To get the natural width of the textarea element, we do a simple calculation based on the 'cols' config.
178 * We use hard-coded numbers to approximate what browsers do natively, to avoid having to read any styles which
179 * would hurt performance. Overrides Labelable method.
182 getBodyNaturalWidth: function() {
183 return Math.round(this.cols * 6.5) + 20;