Upgrade to ExtJS 4.0.0 - Released 04/26/2011
[extjs.git] / docs / source / Editor.html
index b9852b6..6308584 100644 (file)
-<html>
-<head>
-  <title>The source code</title>
-    <link href="../resources/prettify/prettify.css" type="text/css" rel="stylesheet" />
-    <script type="text/javascript" src="../resources/prettify/prettify.js"></script>
-</head>
-<body  onload="prettyPrint();">
-    <pre class="prettyprint lang-js">/*!
- * Ext JS Library 3.0.3
- * Copyright(c) 2006-2009 Ext JS, LLC
- * licensing@extjs.com
- * http://www.extjs.com/license
- */
-<div id="cls-Ext.Editor"></div>/**
- * @class Ext.Editor
+<!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-Editor-method-constructor'><span id='Ext-Editor'>/**
+</span></span> * @class Ext.Editor
  * @extends Ext.Component
- * A base editor field that handles displaying/hiding on demand and has some built-in sizing and event handling logic.
+ *
+ * &lt;p&gt;
+ * The Editor class is used to provide inline editing for elements on the page. The editor
+ * is backed by a {@link Ext.form.field.Field} that will be displayed to edit the underlying content.
+ * The editor is a floating Component, when the editor is shown it is automatically aligned to
+ * display over the top of the bound element it is editing. The Editor contains several options
+ * for how to handle key presses:
+ * &lt;ul&gt;
+ * &lt;li&gt;{@link #completeOnEnter}&lt;/li&gt;
+ * &lt;li&gt;{@link #cancelOnEsc}&lt;/li&gt;
+ * &lt;li&gt;{@link #swallowKeys}&lt;/li&gt;
+ * &lt;/ul&gt;
+ * It also has options for how to use the value once the editor has been activated:
+ * &lt;ul&gt;
+ * &lt;li&gt;{@link #revertInvalid}&lt;/li&gt;
+ * &lt;li&gt;{@link #ignoreNoChange}&lt;/li&gt;
+ * &lt;li&gt;{@link #updateEl}&lt;/li&gt;
+ * &lt;/ul&gt;
+ * Sample usage:
+ * &lt;/p&gt;
+ * &lt;pre&gt;&lt;code&gt;
+var editor = new Ext.Editor({
+    updateEl: true, // update the innerHTML of the bound element when editing completes
+    field: {
+        xtype: 'textfield'
+    }
+});
+var el = Ext.get('my-text'); // The element to 'edit'
+editor.startEdit(el); // The value of the field will be taken as the innerHTML of the element.
+ * &lt;/code&gt;&lt;/pre&gt;
+ * {@img Ext.Editor/Ext.Editor.png Ext.Editor component}
+ *
  * @constructor
  * Create a new Editor
  * @param {Object} config The config object
  * @xtype editor
  */
-Ext.Editor = function(field, config){
-    if(field.field){
-        this.field = Ext.create(field.field, 'textfield');
-        config = Ext.apply({}, field); // copy so we don't disturb original config
-        delete config.field;
-    }else{
-        this.field = field;
-    }
-    Ext.Editor.superclass.constructor.call(this, config);
-};
+Ext.define('Ext.Editor', {
+
+    /* Begin Definitions */
+
+    extend: 'Ext.Component',
+
+    alias: 'widget.editor',
+
+    requires: ['Ext.layout.component.Editor'],
+
+    /* End Definitions */
+
+   componentLayout: 'editor',
 
-Ext.extend(Ext.Editor, Ext.Component, {
-    <div id="cfg-Ext.Editor-field"></div>/**
-    * @cfg {Ext.form.Field} field
+<span id='Ext-Editor-cfg-field'>    /**
+</span>    * @cfg {Ext.form.field.Field} field
     * The Field object (or descendant) or config object for field
     */
-    <div id="cfg-Ext.Editor-allowBlur"></div>/**
-     * @cfg {Boolean} allowBlur
+
+<span id='Ext-Editor-cfg-allowBlur'>    /**
+</span>     * @cfg {Boolean} allowBlur
      * True to {@link #completeEdit complete the editing process} if in edit mode when the
-     * field is blurred. Defaults to <tt>false</tt>.
+     * field is blurred. Defaults to &lt;tt&gt;true&lt;/tt&gt;.
      */
-    <div id="cfg-Ext.Editor-autoSize"></div>/**
-     * @cfg {Boolean/String} autoSize
-     * True for the editor to automatically adopt the size of the underlying field, "width" to adopt the width only,
-     * or "height" to adopt the height only, "none" to always use the field dimensions. (defaults to false)
+    allowBlur: true,
+
+<span id='Ext-Editor-cfg-autoSize'>    /**
+</span>     * @cfg {Boolean/Object} autoSize
+     * True for the editor to automatically adopt the size of the underlying field. Otherwise, an object
+     * can be passed to indicate where to get each dimension. The available properties are 'boundEl' and
+     * 'field'. If a dimension is not specified, it will use the underlying height/width specified on
+     * the editor object.
+     * Examples:
+     * &lt;pre&gt;&lt;code&gt;
+autoSize: true // The editor will be sized to the height/width of the field
+
+height: 21,
+autoSize: {
+    width: 'boundEl' // The width will be determined by the width of the boundEl, the height from the editor (21)
+}
+
+autoSize: {
+    width: 'field', // Width from the field
+    height: 'boundEl' // Height from the boundEl
+}
+     * &lt;/pre&gt;&lt;/code&gt;
      */
-    <div id="cfg-Ext.Editor-revertInvalid"></div>/**
-     * @cfg {Boolean} revertInvalid
+
+<span id='Ext-Editor-cfg-revertInvalid'>    /**
+</span>     * @cfg {Boolean} revertInvalid
      * True to automatically revert the field value and cancel the edit when the user completes an edit and the field
      * validation fails (defaults to true)
      */
-    <div id="cfg-Ext.Editor-ignoreNoChange"></div>/**
-     * @cfg {Boolean} ignoreNoChange
+    revertInvalid: true,
+
+<span id='Ext-Editor-cfg-ignoreNoChange'>    /**
+</span>     * @cfg {Boolean} ignoreNoChange
      * True to skip the edit completion process (no save, no events fired) if the user completes an edit and
      * the value has not changed (defaults to false).  Applies only to string values - edits for other data types
      * will never be ignored.
      */
-    <div id="cfg-Ext.Editor-hideEl"></div>/**
-     * @cfg {Boolean} hideEl
+
+<span id='Ext-Editor-cfg-hideEl'>    /**
+</span>     * @cfg {Boolean} hideEl
      * False to keep the bound element visible while the editor is displayed (defaults to true)
      */
-    <div id="cfg-Ext.Editor-value"></div>/**
-     * @cfg {Mixed} value
-     * The data value of the underlying field (defaults to "")
+
+<span id='Ext-Editor-cfg-value'>    /**
+</span>     * @cfg {Mixed} value
+     * The data value of the underlying field (defaults to &quot;&quot;)
+     */
+    value : '',
+
+<span id='Ext-Editor-cfg-alignment'>    /**
+</span>     * @cfg {String} alignment
+     * The position to align to (see {@link Ext.core.Element#alignTo} for more details, defaults to &quot;c-c?&quot;).
      */
-    value : "",
-    <div id="cfg-Ext.Editor-alignment"></div>/**
-     * @cfg {String} alignment
-     * The position to align to (see {@link Ext.Element#alignTo} for more details, defaults to "c-c?").
+    alignment: 'c-c?',
+
+<span id='Ext-Editor-cfg-offsets'>    /**
+</span>     * @cfg {Array} offsets
+     * The offsets to use when aligning (see {@link Ext.core.Element#alignTo} for more details. Defaults to &lt;tt&gt;[0, 0]&lt;/tt&gt;.
      */
-    alignment: "c-c?",
-    <div id="cfg-Ext.Editor-shadow"></div>/**
-     * @cfg {Boolean/String} shadow "sides" for sides/bottom only, "frame" for 4-way shadow, and "drop"
-     * for bottom-right shadow (defaults to "frame")
+    offsets: [0, 0],
+
+<span id='Ext-Editor-cfg-shadow'>    /**
+</span>     * @cfg {Boolean/String} shadow &quot;sides&quot; for sides/bottom only, &quot;frame&quot; for 4-way shadow, and &quot;drop&quot;
+     * for bottom-right shadow (defaults to &quot;frame&quot;)
      */
-    shadow : "frame",
-    <div id="cfg-Ext.Editor-constrain"></div>/**
-     * @cfg {Boolean} constrain True to constrain the editor to the viewport
+    shadow : 'frame',
+
+<span id='Ext-Editor-cfg-constrain'>    /**
+</span>     * @cfg {Boolean} constrain True to constrain the editor to the viewport
      */
     constrain : false,
-    <div id="cfg-Ext.Editor-swallowKeys"></div>/**
-     * @cfg {Boolean} swallowKeys Handle the keydown/keypress events so they don't propagate (defaults to true)
+
+<span id='Ext-Editor-cfg-swallowKeys'>    /**
+</span>     * @cfg {Boolean} swallowKeys Handle the keydown/keypress events so they don't propagate (defaults to true)
      */
     swallowKeys : true,
-    <div id="cfg-Ext.Editor-completeOnEnter"></div>/**
-     * @cfg {Boolean} completeOnEnter True to complete the edit when the enter key is pressed. Defaults to <tt>true</tt>.
+
+<span id='Ext-Editor-cfg-completeOnEnter'>    /**
+</span>     * @cfg {Boolean} completeOnEnter True to complete the edit when the enter key is pressed. Defaults to &lt;tt&gt;true&lt;/tt&gt;.
      */
     completeOnEnter : true,
-    <div id="cfg-Ext.Editor-cancelOnEsc"></div>/**
-     * @cfg {Boolean} cancelOnEsc True to cancel the edit when the escape key is pressed. Defaults to <tt>true</tt>.
+
+<span id='Ext-Editor-cfg-cancelOnEsc'>    /**
+</span>     * @cfg {Boolean} cancelOnEsc True to cancel the edit when the escape key is pressed. Defaults to &lt;tt&gt;true&lt;/tt&gt;.
      */
     cancelOnEsc : true,
-    <div id="cfg-Ext.Editor-updateEl"></div>/**
-     * @cfg {Boolean} updateEl True to update the innerHTML of the bound element when the update completes (defaults to false)
+
+<span id='Ext-Editor-cfg-updateEl'>    /**
+</span>     * @cfg {Boolean} updateEl True to update the innerHTML of the bound element when the update completes (defaults to false)
      */
     updateEl : false,
 
-    initComponent : function(){
-        Ext.Editor.superclass.initComponent.call(this);
-        this.addEvents(
-            <div id="event-Ext.Editor-beforestartedit"></div>/**
-             * @event beforestartedit
+<span id='Ext-Editor-cfg-parentEl'>    /**
+</span>     * @cfg {Mixed} parentEl An element to render to. Defaults to the &lt;tt&gt;document.body&lt;/tt&gt;.
+     */
+
+    // private overrides
+    hidden: true,
+    baseCls: Ext.baseCSSPrefix + 'editor',
+
+    initComponent : function() {
+        var me = this,
+            field = me.field = Ext.ComponentManager.create(me.field, 'textfield');
+
+        Ext.apply(field, {
+            inEditor: true,
+            msgTarget: field.msgTarget == 'title' ? 'title' :  'qtip'
+        });
+        me.mon(field, {
+            scope: me,
+            blur: {
+                fn: me.onBlur,
+                // slight delay to avoid race condition with startEdits (e.g. grid view refresh)
+                delay: 1
+            },
+            specialkey: me.onSpecialKey
+        });
+
+        if (field.grow) {
+            me.mon(field, 'autosize', me.onAutoSize,  me, {delay: 1});
+        }
+        me.floating = {
+            constrain: me.constrain
+        };
+
+        me.callParent(arguments);
+
+        me.addEvents(
+<span id='Ext-Editor-event-beforestartedit'>            /**
+</span>             * @event beforestartedit
              * Fires when editing is initiated, but before the value changes.  Editing can be canceled by returning
              * false from the handler of this event.
-             * @param {Editor} this
-             * @param {Ext.Element} boundEl The underlying element bound to this editor
+             * @param {Ext.Editor} this
+             * @param {Ext.core.Element} boundEl The underlying element bound to this editor
              * @param {Mixed} value The field value being set
              */
-            "beforestartedit",
-            <div id="event-Ext.Editor-startedit"></div>/**
-             * @event startedit
+            'beforestartedit',
+<span id='Ext-Editor-event-startedit'>            /**
+</span>             * @event startedit
              * Fires when this editor is displayed
-             * @param {Ext.Element} boundEl The underlying element bound to this editor
+             * @param {Ext.Editor} this
+             * @param {Ext.core.Element} boundEl The underlying element bound to this editor
              * @param {Mixed} value The starting field value
              */
-            "startedit",
-            <div id="event-Ext.Editor-beforecomplete"></div>/**
-             * @event beforecomplete
+            'startedit',
+<span id='Ext-Editor-event-beforecomplete'>            /**
+</span>             * @event beforecomplete
              * Fires after a change has been made to the field, but before the change is reflected in the underlying
              * field.  Saving the change to the field can be canceled by returning false from the handler of this event.
              * Note that if the value has not changed and ignoreNoChange = true, the editing will still end but this
@@ -126,65 +217,53 @@ Ext.extend(Ext.Editor, Ext.Component, {
              * @param {Mixed} value The current field value
              * @param {Mixed} startValue The original field value
              */
-            "beforecomplete",
-            <div id="event-Ext.Editor-complete"></div>/**
-             * @event complete
+            'beforecomplete',
+<span id='Ext-Editor-event-complete'>            /**
+</span>             * @event complete
              * Fires after editing is complete and any changed value has been written to the underlying field.
-             * @param {Editor} this
+             * @param {Ext.Editor} this
              * @param {Mixed} value The current field value
              * @param {Mixed} startValue The original field value
              */
-            "complete",
-            <div id="event-Ext.Editor-canceledit"></div>/**
-             * @event canceledit
+            'complete',
+<span id='Ext-Editor-event-canceledit'>            /**
+</span>             * @event canceledit
              * Fires after editing has been canceled and the editor's value has been reset.
-             * @param {Editor} this
+             * @param {Ext.Editor} this
              * @param {Mixed} value The user-entered field value that was discarded
              * @param {Mixed} startValue The original field value that was set back into the editor after cancel
              */
-            "canceledit",
-            <div id="event-Ext.Editor-specialkey"></div>/**
-             * @event specialkey
+            'canceledit',
+<span id='Ext-Editor-event-specialkey'>            /**
+</span>             * @event specialkey
              * Fires when any key related to navigation (arrows, tab, enter, esc, etc.) is pressed.  You can check
              * {@link Ext.EventObject#getKey} to determine which key was pressed.
-             * @param {Ext.form.Field} this
-             * @param {Ext.EventObject} e The event object
+             * @param {Ext.Editor} this
+             * @param {Ext.form.field.Field} The field attached to this editor
+             * @param {Ext.EventObject} event The event object
              */
-            "specialkey"
+            'specialkey'
         );
     },
 
     // private
-    onRender : function(ct, position){
-        this.el = new Ext.Layer({
-            shadow: this.shadow,
-            cls: "x-editor",
-            parentEl : ct,
-            shim : this.shim,
-            shadowOffset: this.shadowOffset || 4,
-            id: this.id,
-            constrain: this.constrain
-        });
-        if(this.zIndex){
-            this.el.setZIndex(this.zIndex);
-        }
-        this.el.setStyle("overflow", Ext.isGecko ? "auto" : "hidden");
-        if(this.field.msgTarget != 'title'){
-            this.field.msgTarget = 'qtip';
-        }
-        this.field.inEditor = true;
-        this.mon(this.field, {
-            scope: this,
-            blur: this.onBlur,
-            specialkey: this.onSpecialKey
-        });
-        if(this.field.grow){
-            this.mon(this.field, "autosize", this.el.sync,  this.el, {delay:1});
-        }
-        this.field.render(this.el).show();
-        this.field.getEl().dom.name = '';
-        if(this.swallowKeys){
-            this.field.el.swallowEvent([
+    onAutoSize: function(){
+        this.doComponentLayout();
+    },
+
+    // private
+    onRender : function(ct, position) {
+        var me = this,
+            field = me.field;
+
+        me.callParent(arguments);
+
+        field.render(me.el);
+        //field.hide();
+        // Ensure the field doesn't get submitted as part of any form
+        field.inputEl.dom.name = '';
+        if (me.swallowKeys) {
+            field.inputEl.swallowEvent([
                 'keypress', // *** Opera
                 'keydown'   // *** all other browsers
             ]);
@@ -192,201 +271,210 @@ Ext.extend(Ext.Editor, Ext.Component, {
     },
 
     // private
-    onSpecialKey : function(field, e){
-        var key = e.getKey(),
-            complete = this.completeOnEnter && key == e.ENTER,
-            cancel = this.cancelOnEsc && key == e.ESC;
-        if(complete || cancel){
-            e.stopEvent();
-            if(complete){
-                this.completeEdit();
-            }else{
-                this.cancelEdit();
-            }
-            if(field.triggerBlur){
-                field.triggerBlur(); 
-            }
+    onSpecialKey : function(field, event) {
+        var me = this,
+            key = event.getKey(),
+            complete = me.completeOnEnter &amp;&amp; key == event.ENTER,
+            cancel = me.cancelOnEsc &amp;&amp; key == event.ESC;
+
+        if (complete || cancel) {
+            event.stopEvent();
+            // Must defer this slightly to prevent exiting edit mode before the field's own
+            // key nav can handle the enter key, e.g. selecting an item in a combobox list
+            Ext.defer(function() {
+                if (complete) {
+                    me.completeEdit();
+                } else {
+                    me.cancelEdit();
+                }
+                if (field.triggerBlur) {
+                    field.triggerBlur();
+                }
+            }, 10);
         }
-        this.fireEvent('specialkey', field, e);
+
+        this.fireEvent('specialkey', this, field, event);
     },
 
-    <div id="method-Ext.Editor-startEdit"></div>/**
-     * Starts the editing process and shows the editor.
+<span id='Ext-Editor-method-startEdit'>    /**
+</span>     * Starts the editing process and shows the editor.
      * @param {Mixed} el The element to edit
      * @param {String} value (optional) A value to initialize the editor with. If a value is not provided, it defaults
       * to the innerHTML of el.
      */
-    startEdit : function(el, value){
-        if(this.editing){
-            this.completeEdit();
-        }
-        this.boundEl = Ext.get(el);
-        var v = value !== undefined ? value : this.boundEl.dom.innerHTML;
-        if(!this.rendered){
-            this.render(this.parentEl || document.body);
-        }
-        if(this.fireEvent("beforestartedit", this, this.boundEl, v) !== false){
-            this.startValue = v;
-            this.field.setValue(v);
-            this.doAutoSize();
-            this.el.alignTo(this.boundEl, this.alignment);
-            this.editing = true;
-            this.show();
-        }
-    },
+    startEdit : function(el, value) {
+        var me = this,
+            field = me.field;
 
-    // private
-    doAutoSize : function(){
-        if(this.autoSize){
-            var sz = this.boundEl.getSize(),
-                fs = this.field.getSize();
-
-            switch(this.autoSize){
-                case "width":
-                    this.setSize(sz.width, fs.height);
-                    break;
-                case "height":
-                    this.setSize(fs.width, sz.height);
-                    break;
-                case "none":
-                    this.setSize(fs.width, fs.height);
-                    break;
-                default:
-                    this.setSize(sz.width, sz.height);
-            }
+        me.completeEdit();
+        me.boundEl = Ext.get(el);
+        value = Ext.isDefined(value) ? value : me.boundEl.dom.innerHTML;
+
+        if (!me.rendered) {
+            me.render(me.parentEl || document.body);
         }
-    },
 
-    <div id="method-Ext.Editor-setSize"></div>/**
-     * Sets the height and width of this editor.
-     * @param {Number} width The new width
-     * @param {Number} height The new height
-     */
-    setSize : function(w, h){
-        delete this.field.lastSize;
-        this.field.setSize(w, h);
-        if(this.el){
-            if(Ext.isGecko2 || Ext.isOpera){
-                // prevent layer scrollbars
-                this.el.setSize(w, h);
+        if (me.fireEvent('beforestartedit', me, me.boundEl, value) !== false) {
+            me.startValue = value;
+            me.show();
+            field.reset();
+            field.setValue(value);
+            me.realign(true);
+            field.focus(false, 10);
+            if (field.autoSize) {
+                field.autoSize();
             }
-            this.el.sync();
+            me.editing = true;
         }
     },
 
-    <div id="method-Ext.Editor-realign"></div>/**
-     * Realigns the editor to the bound field based on the current alignment config value.
+<span id='Ext-Editor-method-realign'>    /**
+</span>     * Realigns the editor to the bound field based on the current alignment config value.
+     * @param {Boolean} autoSize (optional) True to size the field to the dimensions of the bound element.
      */
-    realign : function(){
-        this.el.alignTo(this.boundEl, this.alignment);
+    realign : function(autoSize) {
+        var me = this;
+        if (autoSize === true) {
+            me.doComponentLayout();
+        }
+        me.alignTo(me.boundEl, me.alignment, me.offsets);
     },
 
-    <div id="method-Ext.Editor-completeEdit"></div>/**
-     * Ends the editing process, persists the changed value to the underlying field, and hides the editor.
+<span id='Ext-Editor-method-completeEdit'>    /**
+</span>     * Ends the editing process, persists the changed value to the underlying field, and hides the editor.
      * @param {Boolean} remainVisible Override the default behavior and keep the editor visible after edit (defaults to false)
      */
-    completeEdit : function(remainVisible){
-        if(!this.editing){
+    completeEdit : function(remainVisible) {
+        var me = this,
+            field = me.field,
+            value;
+
+        if (!me.editing) {
             return;
         }
-        var v = this.getValue();
-        if(!this.field.isValid()){
-            if(this.revertInvalid !== false){
-                this.cancelEdit(remainVisible);
+
+        // Assert combo values first
+        if (field.assertValue) {
+            field.assertValue();
+        }
+
+        value = me.getValue();
+        if (!field.isValid()) {
+            if (me.revertInvalid !== false) {
+                me.cancelEdit(remainVisible);
             }
             return;
         }
-        if(String(v) === String(this.startValue) && this.ignoreNoChange){
-            this.hideEdit(remainVisible);
+
+        if (String(value) === String(me.startValue) &amp;&amp; me.ignoreNoChange) {
+            me.hideEdit(remainVisible);
             return;
         }
-        if(this.fireEvent("beforecomplete", this, v, this.startValue) !== false){
-            v = this.getValue();
-            if(this.updateEl && this.boundEl){
-                this.boundEl.update(v);
+
+        if (me.fireEvent('beforecomplete', me, value, me.startValue) !== false) {
+            // Grab the value again, may have changed in beforecomplete
+            value = me.getValue();
+            if (me.updateEl &amp;&amp; me.boundEl) {
+                me.boundEl.update(value);
             }
-            this.hideEdit(remainVisible);
-            this.fireEvent("complete", this, v, this.startValue);
+            me.hideEdit(remainVisible);
+            me.fireEvent('complete', me, value, me.startValue);
         }
     },
 
     // private
-    onShow : function(){
-        this.el.show();
-        if(this.hideEl !== false){
-            this.boundEl.hide();
+    onShow : function() {
+        var me = this;
+
+        me.callParent(arguments);
+        if (me.hideEl !== false) {
+            me.boundEl.hide();
         }
-        this.field.show().focus(false, true);
-        this.fireEvent("startedit", this.boundEl, this.startValue);
+        me.fireEvent(&quot;startedit&quot;, me.boundEl, me.startValue);
     },
 
-    <div id="method-Ext.Editor-cancelEdit"></div>/**
-     * Cancels the editing process and hides the editor without persisting any changes.  The field value will be
+<span id='Ext-Editor-method-cancelEdit'>    /**
+</span>     * Cancels the editing process and hides the editor without persisting any changes.  The field value will be
      * reverted to the original starting value.
      * @param {Boolean} remainVisible Override the default behavior and keep the editor visible after
      * cancel (defaults to false)
      */
-    cancelEdit : function(remainVisible){
-        if(this.editing){
-            var v = this.getValue();
-            this.setValue(this.startValue);
-            this.hideEdit(remainVisible);
-            this.fireEvent("canceledit", this, v, this.startValue);
+    cancelEdit : function(remainVisible) {
+        var me = this,
+            startValue = me.startValue,
+            value;
+
+        if (me.editing) {
+            value = me.getValue();
+            me.setValue(startValue);
+            me.hideEdit(remainVisible);
+            me.fireEvent('canceledit', me, value, startValue);
         }
     },
-    
+
     // private
-    hideEdit: function(remainVisible){
-        if(remainVisible !== true){
+    hideEdit: function(remainVisible) {
+        if (remainVisible !== true) {
             this.editing = false;
             this.hide();
         }
     },
 
     // private
-    onBlur : function(){
-        if(this.allowBlur !== true && this.editing){
-            this.completeEdit();
+    onBlur : function() {
+        var me = this;
+
+        // selectSameEditor flag allows the same editor to be started without onBlur firing on itself
+        if(me.allowBlur === true &amp;&amp; me.editing &amp;&amp; me.selectSameEditor !== true) {
+            me.completeEdit();
         }
     },
 
     // private
-    onHide : function(){
-        if(this.editing){
-            this.completeEdit();
+    onHide : function() {
+        var me = this,
+            field = me.field;
+
+        if (me.editing) {
+            me.completeEdit();
             return;
         }
-        this.field.blur();
-        if(this.field.collapse){
-            this.field.collapse();
+        field.blur();
+        if (field.collapse) {
+            field.collapse();
         }
-        this.el.hide();
-        if(this.hideEl !== false){
-            this.boundEl.show();
+
+        //field.hide();
+        if (me.hideEl !== false) {
+            me.boundEl.show();
         }
+        me.callParent(arguments);
     },
 
-    <div id="method-Ext.Editor-setValue"></div>/**
-     * Sets the data value of the editor
+<span id='Ext-Editor-method-setValue'>    /**
+</span>     * Sets the data value of the editor
      * @param {Mixed} value Any valid value supported by the underlying field
      */
-    setValue : function(v){
-        this.field.setValue(v);
+    setValue : function(value) {
+        this.field.setValue(value);
     },
 
-    <div id="method-Ext.Editor-getValue"></div>/**
-     * Gets the data value of the editor
+<span id='Ext-Editor-method-getValue'>    /**
+</span>     * Gets the data value of the editor
      * @return {Mixed} The data value
      */
-    getValue : function(){
+    getValue : function() {
         return this.field.getValue();
     },
 
-    beforeDestroy : function(){
-        Ext.destroy(this.field);
-        this.field = null;
+    beforeDestroy : function() {
+        var me = this;
+
+        Ext.destroy(me.field);
+        delete me.field;
+        delete me.parentEl;
+        delete me.boundEl;
+
+        me.callParent(arguments);
     }
-});
-Ext.reg('editor', Ext.Editor);</pre>
-</body>
-</html>
\ No newline at end of file
+});</pre></pre></body></html>
\ No newline at end of file