/* * Based on: * Ext JS Library 1.1.1 * Copyright(c) 2006-2007, Ext JS, LLC. * * Originally Released Under LGPL - original licence link has changed is not relivant. * * Fork - LGPL * <script type="text/javascript"> */ /** * @class Roo.form.TextArea * @extends Roo.form.TextField * Multiline text field. Can be used as a direct replacement for traditional textarea fields, plus adds * support for auto-sizing. * @constructor * Creates a new TextArea * @param {Object} config Configuration options */ Roo.form.TextArea = function(config){ Roo.form.TextArea.superclass.constructor.call(this, config); // these are provided exchanges for backwards compat // minHeight/maxHeight were replaced by growMin/growMax to be // compatible with TextField growing config values if(this.minHeight !== undefined){ this.growMin = this.minHeight; } if(this.maxHeight !== undefined){ this.growMax = this.maxHeight; } }; Roo.extend(Roo.form.TextArea, Roo.form.TextField, { /** * @cfg {Number} growMin The minimum height to allow when grow = true (defaults to 60) */ growMin : 60, /** * @cfg {Number} growMax The maximum height to allow when grow = true (defaults to 1000) */ growMax: 1000, /** * @cfg {Boolean} preventScrollbars True to prevent scrollbars from appearing regardless of how much text is * in the field (equivalent to setting overflow: hidden, defaults to false) */ preventScrollbars: false, /** * @cfg {String/Object} autoCreate A DomHelper element spec, or true for a default element spec (defaults to * {tag: "textarea", style: "width:300px;height:60px;", autocomplete: "off"}) */ // private onRender : function(ct, position){ if(!this.el){ this.defaultAutoCreate = { tag: "textarea", style:"width:300px;height:60px;", autocomplete: "new-password" }; } Roo.form.TextArea.superclass.onRender.call(this, ct, position); if(this.grow){ this.textSizeEl = Roo.DomHelper.append(document.body, { tag: "pre", cls: "x-form-grow-sizer" }); if(this.preventScrollbars){ this.el.setStyle("overflow", "hidden"); } this.el.setHeight(this.growMin); } }, onDestroy : function(){ if(this.textSizeEl){ this.textSizeEl.parentNode.removeChild(this.textSizeEl); } Roo.form.TextArea.superclass.onDestroy.call(this); }, // private onKeyUp : function(e){ if(!e.isNavKeyPress() || e.getKey() == e.ENTER){ this.autoSize(); } }, /** * Automatically grows the field to accomodate the height of the text up to the maximum field height allowed. * This only takes effect if grow = true, and fires the autosize event if the height changes. */ autoSize : function(){ if(!this.grow || !this.textSizeEl){ return; } var el = this.el; var v = el.dom.value; var ts = this.textSizeEl; ts.innerHTML = ''; ts.appendChild(document.createTextNode(v)); v = ts.innerHTML; Roo.fly(ts).setWidth(this.el.getWidth()); if(v.length < 1){ v = "&#160;&#160;"; }else{ if(Roo.isIE){ v = v.replace(/\n/g, '<p>&#160;</p>'); } v += "&#160;\n&#160;"; } ts.innerHTML = v; var h = Math.min(this.growMax, Math.max(ts.offsetHeight, this.growMin)); if(h != this.lastHeight){ this.lastHeight = h; this.el.setHeight(h); this.fireEvent("autosize", this, h); } } });