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-field-TextArea-method-constructor'><span id='Ext-form-field-TextArea'>/**
19 </span></span> * @class Ext.form.field.TextArea
20 * @extends Ext.form.field.Text
22 This class creates a multiline text field, which can be used as a direct replacement for traditional
23 textarea fields. In addition, it supports automatically {@link #grow growing} the height of the textarea to
26 All of the configuration options from {@link Ext.form.field.Text} can be used on TextArea.
27 {@img Ext.form.TextArea/Ext.form.TextArea.png Ext.form.TextArea component}
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}. These
45 allow you to set the minimum and maximum grow heights for the textarea.
48 * Creates a new TextArea
49 * @param {Object} config Configuration options
50 * @xtype textareafield
51 * @docauthor Robert Dougan <rob@sencha.com>
53 Ext.define('Ext.form.field.TextArea', {
54 extend:'Ext.form.field.Text',
55 alias: ['widget.textareafield', 'widget.textarea'],
56 alternateClassName: 'Ext.form.TextArea',
57 requires: ['Ext.XTemplate', 'Ext.layout.component.field.TextArea'],
60 '<textarea id="{id}" ',
61 '<tpl if="name">name="{name}" </tpl>',
62 '<tpl if="rows">rows="{rows}" </tpl>',
63 '<tpl if="cols">cols="{cols}" </tpl>',
64 '<tpl if="tabIdx">tabIndex="{tabIdx}" </tpl>',
65 'class="{fieldCls} {typeCls}" ',
66 'autocomplete="off">',
74 <span id='Ext-form-field-TextArea-cfg-growMin'> /**
75 </span> * @cfg {Number} growMin The minimum height to allow when <tt>{@link Ext.form.field.Text#grow grow}=true</tt>
76 * (defaults to <tt>60</tt>)
80 <span id='Ext-form-field-TextArea-cfg-growMax'> /**
81 </span> * @cfg {Number} growMax The maximum height to allow when <tt>{@link Ext.form.field.Text#grow grow}=true</tt>
82 * (defaults to <tt>1000</tt>)
86 <span id='Ext-form-field-TextArea-cfg-growAppend'> /**
87 </span> * @cfg {String} growAppend
88 * A string that will be appended to the field's current value for the purposes of calculating the target
89 * field size. Only used when the {@link #grow} config is <tt>true</tt>. Defaults to a newline for TextArea
90 * to ensure there is always a space below the current line.
94 <span id='Ext-form-field-TextArea-cfg-cols'> /**
95 </span> * @cfg {Number} cols An initial value for the 'cols' attribute on the textarea element. This is only
96 * used if the component has no configured {@link #width} and is not given a width by its container's
97 * layout. Defaults to <tt>20</tt>.
101 <span id='Ext-form-field-TextArea-cfg-cols'> /**
102 </span> * @cfg {Number} cols An initial value for the 'cols' attribute on the textarea element. This is only
103 * used if the component has no configured {@link #width} and is not given a width by its container's
104 * layout. Defaults to <tt>4</tt>.
108 <span id='Ext-form-field-TextArea-cfg-enterIsSpecial'> /**
109 </span> * @cfg {Boolean} enterIsSpecial
110 * True if you want the enter key to be classed as a <tt>special</tt> key. Special keys are generally navigation
111 * keys (arrows, space, enter). Setting the config property to <tt>true</tt> would mean that you could not insert
112 * returns into the textarea.
113 * (defaults to <tt>false</tt>)
115 enterIsSpecial: false,
117 <span id='Ext-form-field-TextArea-cfg-preventScrollbars'> /**
118 </span> * @cfg {Boolean} preventScrollbars <tt>true</tt> to prevent scrollbars from appearing regardless of how much text is
119 * in the field. This option is only relevant when {@link #grow} is <tt>true</tt>. Equivalent to setting overflow: hidden, defaults to
120 * <tt>false</tt>.
122 preventScrollbars: false,
125 componentLayout: 'textareafield',
128 onRender: function(ct, position) {
130 Ext.applyIf(me.subTplData, {
135 me.callParent(arguments);
139 afterRender: function(){
142 me.callParent(arguments);
145 if (me.preventScrollbars) {
146 me.inputEl.setStyle('overflow', 'hidden');
148 me.inputEl.setHeight(me.growMin);
153 fireKey: function(e) {
154 if (e.isSpecialKey() && (this.enterIsSpecial || (e.getKey() !== e.ENTER || e.hasModifier()))) {
155 this.fireEvent('specialkey', this, e);
159 <span id='Ext-form-field-TextArea-method-autoSize'> /**
160 </span> * Automatically grows the field to accomodate the height of the text up to the maximum field height allowed.
161 * This only takes effect if <tt>{@link #grow} = true</tt>, and fires the {@link #autosize} event if
162 * the height changes.
164 autoSize: function() {
168 if (me.grow && me.rendered) {
169 me.doComponentLayout();
170 height = me.inputEl.getHeight();
171 if (height !== me.lastInputHeight) {
172 me.fireEvent('autosize', height);
173 me.lastInputHeight = height;
179 initAria: function() {
180 this.callParent(arguments);
181 this.getActionEl().dom.setAttribute('aria-multiline', true);
184 <span id='Ext-form-field-TextArea-method-getBodyNaturalWidth'> /**
185 </span> * @protected override
186 * To get the natural width of the textarea element, we do a simple calculation based on the
187 * 'cols' config. We use hard-coded numbers to approximate what browsers do natively,
188 * to avoid having to read any styles which would hurt performance.
190 getBodyNaturalWidth: function() {
191 return Math.round(this.cols * 6.5) + 20;