1 <!DOCTYPE html><html><head><title>Sencha Documentation Project</title><link rel="stylesheet" href="../reset.css" type="text/css"><link rel="stylesheet" href="../prettify.css" type="text/css"><link rel="stylesheet" href="../prettify_sa.css" type="text/css"><script type="text/javascript" src="../prettify.js"></script></head><body onload="prettyPrint()"><pre class="prettyprint"><pre><span id='Ext-form.field.TextArea-method-constructor'><span id='Ext-form.field.TextArea'>/**
2 </span></span> * @class Ext.form.field.TextArea
3 * @extends Ext.form.field.Text
5 This class creates a multiline text field, which can be used as a direct replacement for traditional
6 textarea fields. In addition, it supports automatically {@link #grow growing} the height of the textarea to
9 All of the configuration options from {@link Ext.form.field.Text} can be used on TextArea.
10 {@img Ext.form.TextArea/Ext.form.TextArea.png Ext.form.TextArea component}
13 Ext.create('Ext.form.FormPanel', {
14 title : 'Sample TextArea',
17 renderTo : Ext.getBody(),
19 xtype : 'textareafield',
22 fieldLabel: 'Message',
27 Some other useful configuration options when using {@link #grow} are {@link #growMin} and {@link #growMax}. These
28 allow you to set the minimum and maximum grow heights for the textarea.
31 * Creates a new TextArea
32 * @param {Object} config Configuration options
33 * @xtype textareafield
34 * @docauthor Robert Dougan <rob@sencha.com>
36 Ext.define('Ext.form.field.TextArea', {
37 extend:'Ext.form.field.Text',
38 alias: ['widget.textareafield', 'widget.textarea'],
39 alternateClassName: 'Ext.form.TextArea',
40 requires: ['Ext.XTemplate', 'Ext.layout.component.field.TextArea'],
43 '<textarea id="{id}" ',
44 '<tpl if="name">name="{name}" </tpl>',
45 '<tpl if="rows">rows="{rows}" </tpl>',
46 '<tpl if="cols">cols="{cols}" </tpl>',
47 '<tpl if="tabIdx">tabIndex="{tabIdx}" </tpl>',
48 'class="{fieldCls} {typeCls}" ',
49 'autocomplete="off">',
57 <span id='Ext-form.field.TextArea-cfg-growMin'> /**
58 </span> * @cfg {Number} growMin The minimum height to allow when <tt>{@link Ext.form.field.Text#grow grow}=true</tt>
59 * (defaults to <tt>60</tt>)
63 <span id='Ext-form.field.TextArea-cfg-growMax'> /**
64 </span> * @cfg {Number} growMax The maximum height to allow when <tt>{@link Ext.form.field.Text#grow grow}=true</tt>
65 * (defaults to <tt>1000</tt>)
69 <span id='Ext-form.field.TextArea-cfg-growAppend'> /**
70 </span> * @cfg {String} growAppend
71 * A string that will be appended to the field's current value for the purposes of calculating the target
72 * field size. Only used when the {@link #grow} config is <tt>true</tt>. Defaults to a newline for TextArea
73 * to ensure there is always a space below the current line.
77 <span id='Ext-form.field.TextArea-cfg-cols'> /**
78 </span> * @cfg {Number} cols An initial value for the 'cols' attribute on the textarea element. This is only
79 * used if the component has no configured {@link #width} and is not given a width by its container's
80 * layout. Defaults to <tt>20</tt>.
84 <span id='Ext-form.field.TextArea-cfg-cols'> /**
85 </span> * @cfg {Number} cols An initial value for the 'cols' attribute on the textarea element. This is only
86 * used if the component has no configured {@link #width} and is not given a width by its container's
87 * layout. Defaults to <tt>4</tt>.
91 <span id='Ext-form.field.TextArea-cfg-enterIsSpecial'> /**
92 </span> * @cfg {Boolean} enterIsSpecial
93 * True if you want the enter key to be classed as a <tt>special</tt> key. Special keys are generally navigation
94 * keys (arrows, space, enter). Setting the config property to <tt>true</tt> would mean that you could not insert
95 * returns into the textarea.
96 * (defaults to <tt>false</tt>)
98 enterIsSpecial: false,
100 <span id='Ext-form.field.TextArea-cfg-preventScrollbars'> /**
101 </span> * @cfg {Boolean} preventScrollbars <tt>true</tt> to prevent scrollbars from appearing regardless of how much text is
102 * in the field. This option is only relevant when {@link #grow} is <tt>true</tt>. Equivalent to setting overflow: hidden, defaults to
103 * <tt>false</tt>.
105 preventScrollbars: false,
108 componentLayout: 'textareafield',
111 onRender: function(ct, position) {
113 Ext.applyIf(me.subTplData, {
118 me.callParent(arguments);
122 afterRender: function(){
125 me.callParent(arguments);
128 if (me.preventScrollbars) {
129 me.inputEl.setStyle('overflow', 'hidden');
131 me.inputEl.setHeight(me.growMin);
136 fireKey: function(e) {
137 if (e.isSpecialKey() && (this.enterIsSpecial || (e.getKey() !== e.ENTER || e.hasModifier()))) {
138 this.fireEvent('specialkey', this, e);
142 <span id='Ext-form.field.TextArea-method-autoSize'> /**
143 </span> * Automatically grows the field to accomodate the height of the text up to the maximum field height allowed.
144 * This only takes effect if <tt>{@link #grow} = true</tt>, and fires the {@link #autosize} event if
145 * the height changes.
147 autoSize: function() {
151 if (me.grow && me.rendered) {
152 me.doComponentLayout();
153 height = me.inputEl.getHeight();
154 if (height !== me.lastInputHeight) {
155 me.fireEvent('autosize', height);
156 me.lastInputHeight = height;
162 initAria: function() {
163 this.callParent(arguments);
164 this.getActionEl().dom.setAttribute('aria-multiline', true);
167 <span id='Ext-form.field.TextArea-method-getBodyNaturalWidth'> /**
168 </span> * @protected override
169 * To get the natural width of the textarea element, we do a simple calculation based on the
170 * 'cols' config. We use hard-coded numbers to approximate what browsers do natively,
171 * to avoid having to read any styles which would hurt performance.
173 getBodyNaturalWidth: function() {
174 return Math.round(this.cols * 6.5) + 20;
179 </pre></pre></body></html>