3 * Copyright(c) 2006-2010 Sencha Inc.
5 * http://www.sencha.com/license
8 * @class Ext.form.TextArea
9 * @extends Ext.form.TextField
10 * Multiline text field. Can be used as a direct replacement for traditional textarea fields, plus adds
11 * support for auto-sizing.
13 * Creates a new TextArea
14 * @param {Object} config Configuration options
17 Ext.form.TextArea = Ext.extend(Ext.form.TextField, {
19 * @cfg {Number} growMin The minimum height to allow when <tt>{@link Ext.form.TextField#grow grow}=true</tt>
20 * (defaults to <tt>60</tt>)
24 * @cfg {Number} growMax The maximum height to allow when <tt>{@link Ext.form.TextField#grow grow}=true</tt>
25 * (defaults to <tt>1000</tt>)
28 growAppend : ' \n ',
30 enterIsSpecial : false,
33 * @cfg {Boolean} preventScrollbars <tt>true</tt> to prevent scrollbars from appearing regardless of how much text is
34 * in the field. This option is only relevant when {@link #grow} is <tt>true</tt>. Equivalent to setting overflow: hidden, defaults to
37 preventScrollbars: false,
39 * @cfg {String/Object} autoCreate <p>A {@link Ext.DomHelper DomHelper} element spec, or true for a default
40 * element spec. Used to create the {@link Ext.Component#getEl Element} which will encapsulate this Component.
41 * See <tt>{@link Ext.Component#autoEl autoEl}</tt> for details. Defaults to:</p>
42 * <pre><code>{tag: "textarea", style: "width:100px;height:60px;", autocomplete: "off"}</code></pre>
46 onRender : function(ct, position){
48 this.defaultAutoCreate = {
50 style:"width:100px;height:60px;",
54 Ext.form.TextArea.superclass.onRender.call(this, ct, position);
56 this.textSizeEl = Ext.DomHelper.append(document.body, {
57 tag: "pre", cls: "x-form-grow-sizer"
59 if(this.preventScrollbars){
60 this.el.setStyle("overflow", "hidden");
62 this.el.setHeight(this.growMin);
66 onDestroy : function(){
67 Ext.removeNode(this.textSizeEl);
68 Ext.form.TextArea.superclass.onDestroy.call(this);
71 fireKey : function(e){
72 if(e.isSpecialKey() && (this.enterIsSpecial || (e.getKey() != e.ENTER || e.hasModifier()))){
73 this.fireEvent("specialkey", this, e);
78 doAutoSize : function(e){
79 return !e.isNavKeyPress() || e.getKey() == e.ENTER;
83 filterValidation: function(e) {
84 if(!e.isNavKeyPress() || (!this.enterIsSpecial && e.keyCode == e.ENTER)){
85 this.validationTask.delay(this.validationDelay);
90 * Automatically grows the field to accomodate the height of the text up to the maximum field height allowed.
91 * This only takes effect if grow = true, and fires the {@link #autosize} event if the height changes.
94 if(!this.grow || !this.textSizeEl){
98 v = Ext.util.Format.htmlEncode(el.dom.value),
102 Ext.fly(ts).setWidth(this.el.getWidth());
106 v += this.growAppend;
108 v = v.replace(/\n/g, ' <br />');
112 h = Math.min(this.growMax, Math.max(ts.offsetHeight, this.growMin));
113 if(h != this.lastHeight){
115 this.el.setHeight(h);
116 this.fireEvent("autosize", this, h);
120 Ext.reg('textarea', Ext.form.TextArea);