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-Editor-method-constructor'><span id='Ext-Editor'>/**
2 </span></span> * @class Ext.Editor
3 * @extends Ext.Component
6 * The Editor class is used to provide inline editing for elements on the page. The editor
7 * is backed by a {@link Ext.form.field.Field} that will be displayed to edit the underlying content.
8 * The editor is a floating Component, when the editor is shown it is automatically aligned to
9 * display over the top of the bound element it is editing. The Editor contains several options
10 * for how to handle key presses:
12 * <li>{@link #completeOnEnter}</li>
13 * <li>{@link #cancelOnEsc}</li>
14 * <li>{@link #swallowKeys}</li>
16 * It also has options for how to use the value once the editor has been activated:
18 * <li>{@link #revertInvalid}</li>
19 * <li>{@link #ignoreNoChange}</li>
20 * <li>{@link #updateEl}</li>
24 * <pre><code>
25 var editor = new Ext.Editor({
26 updateEl: true, // update the innerHTML of the bound element when editing completes
31 var el = Ext.get('my-text'); // The element to 'edit'
32 editor.startEdit(el); // The value of the field will be taken as the innerHTML of the element.
33 * </code></pre>
34 * {@img Ext.Editor/Ext.Editor.png Ext.Editor component}
38 * @param {Object} config The config object
41 Ext.define('Ext.Editor', {
43 /* Begin Definitions */
45 extend: 'Ext.Component',
47 alias: 'widget.editor',
49 requires: ['Ext.layout.component.Editor'],
53 componentLayout: 'editor',
55 <span id='Ext-Editor-cfg-field'> /**
56 </span> * @cfg {Ext.form.field.Field} field
57 * The Field object (or descendant) or config object for field
60 <span id='Ext-Editor-cfg-allowBlur'> /**
61 </span> * @cfg {Boolean} allowBlur
62 * True to {@link #completeEdit complete the editing process} if in edit mode when the
63 * field is blurred. Defaults to <tt>true</tt>.
67 <span id='Ext-Editor-cfg-autoSize'> /**
68 </span> * @cfg {Boolean/Object} autoSize
69 * True for the editor to automatically adopt the size of the underlying field. Otherwise, an object
70 * can be passed to indicate where to get each dimension. The available properties are 'boundEl' and
71 * 'field'. If a dimension is not specified, it will use the underlying height/width specified on
74 * <pre><code>
75 autoSize: true // The editor will be sized to the height/width of the field
79 width: 'boundEl' // The width will be determined by the width of the boundEl, the height from the editor (21)
83 width: 'field', // Width from the field
84 height: 'boundEl' // Height from the boundEl
86 * </pre></code>
89 <span id='Ext-Editor-cfg-revertInvalid'> /**
90 </span> * @cfg {Boolean} revertInvalid
91 * True to automatically revert the field value and cancel the edit when the user completes an edit and the field
92 * validation fails (defaults to true)
96 <span id='Ext-Editor-cfg-ignoreNoChange'> /**
97 </span> * @cfg {Boolean} ignoreNoChange
98 * True to skip the edit completion process (no save, no events fired) if the user completes an edit and
99 * the value has not changed (defaults to false). Applies only to string values - edits for other data types
100 * will never be ignored.
103 <span id='Ext-Editor-cfg-hideEl'> /**
104 </span> * @cfg {Boolean} hideEl
105 * False to keep the bound element visible while the editor is displayed (defaults to true)
108 <span id='Ext-Editor-cfg-value'> /**
109 </span> * @cfg {Mixed} value
110 * The data value of the underlying field (defaults to "")
114 <span id='Ext-Editor-cfg-alignment'> /**
115 </span> * @cfg {String} alignment
116 * The position to align to (see {@link Ext.core.Element#alignTo} for more details, defaults to "c-c?").
120 <span id='Ext-Editor-cfg-offsets'> /**
121 </span> * @cfg {Array} offsets
122 * The offsets to use when aligning (see {@link Ext.core.Element#alignTo} for more details. Defaults to <tt>[0, 0]</tt>.
126 <span id='Ext-Editor-cfg-shadow'> /**
127 </span> * @cfg {Boolean/String} shadow "sides" for sides/bottom only, "frame" for 4-way shadow, and "drop"
128 * for bottom-right shadow (defaults to "frame")
132 <span id='Ext-Editor-cfg-constrain'> /**
133 </span> * @cfg {Boolean} constrain True to constrain the editor to the viewport
137 <span id='Ext-Editor-cfg-swallowKeys'> /**
138 </span> * @cfg {Boolean} swallowKeys Handle the keydown/keypress events so they don't propagate (defaults to true)
142 <span id='Ext-Editor-cfg-completeOnEnter'> /**
143 </span> * @cfg {Boolean} completeOnEnter True to complete the edit when the enter key is pressed. Defaults to <tt>true</tt>.
145 completeOnEnter : true,
147 <span id='Ext-Editor-cfg-cancelOnEsc'> /**
148 </span> * @cfg {Boolean} cancelOnEsc True to cancel the edit when the escape key is pressed. Defaults to <tt>true</tt>.
152 <span id='Ext-Editor-cfg-updateEl'> /**
153 </span> * @cfg {Boolean} updateEl True to update the innerHTML of the bound element when the update completes (defaults to false)
157 <span id='Ext-Editor-cfg-parentEl'> /**
158 </span> * @cfg {Mixed} parentEl An element to render to. Defaults to the <tt>document.body</tt>.
163 baseCls: Ext.baseCSSPrefix + 'editor',
165 initComponent : function() {
167 field = me.field = Ext.ComponentManager.create(me.field, 'textfield');
171 msgTarget: field.msgTarget == 'title' ? 'title' : 'qtip'
177 // slight delay to avoid race condition with startEdits (e.g. grid view refresh)
180 specialkey: me.onSpecialKey
184 me.mon(field, 'autosize', me.onAutoSize, me, {delay: 1});
187 constrain: me.constrain
190 me.callParent(arguments);
193 <span id='Ext-Editor-event-beforestartedit'> /**
194 </span> * @event beforestartedit
195 * Fires when editing is initiated, but before the value changes. Editing can be canceled by returning
196 * false from the handler of this event.
197 * @param {Ext.Editor} this
198 * @param {Ext.core.Element} boundEl The underlying element bound to this editor
199 * @param {Mixed} value The field value being set
202 <span id='Ext-Editor-event-startedit'> /**
203 </span> * @event startedit
204 * Fires when this editor is displayed
205 * @param {Ext.Editor} this
206 * @param {Ext.core.Element} boundEl The underlying element bound to this editor
207 * @param {Mixed} value The starting field value
210 <span id='Ext-Editor-event-beforecomplete'> /**
211 </span> * @event beforecomplete
212 * Fires after a change has been made to the field, but before the change is reflected in the underlying
213 * field. Saving the change to the field can be canceled by returning false from the handler of this event.
214 * Note that if the value has not changed and ignoreNoChange = true, the editing will still end but this
215 * event will not fire since no edit actually occurred.
216 * @param {Editor} this
217 * @param {Mixed} value The current field value
218 * @param {Mixed} startValue The original field value
221 <span id='Ext-Editor-event-complete'> /**
222 </span> * @event complete
223 * Fires after editing is complete and any changed value has been written to the underlying field.
224 * @param {Ext.Editor} this
225 * @param {Mixed} value The current field value
226 * @param {Mixed} startValue The original field value
229 <span id='Ext-Editor-event-canceledit'> /**
230 </span> * @event canceledit
231 * Fires after editing has been canceled and the editor's value has been reset.
232 * @param {Ext.Editor} this
233 * @param {Mixed} value The user-entered field value that was discarded
234 * @param {Mixed} startValue The original field value that was set back into the editor after cancel
237 <span id='Ext-Editor-event-specialkey'> /**
238 </span> * @event specialkey
239 * Fires when any key related to navigation (arrows, tab, enter, esc, etc.) is pressed. You can check
240 * {@link Ext.EventObject#getKey} to determine which key was pressed.
241 * @param {Ext.Editor} this
242 * @param {Ext.form.field.Field} The field attached to this editor
243 * @param {Ext.EventObject} event The event object
250 onAutoSize: function(){
251 this.doComponentLayout();
255 onRender : function(ct, position) {
259 me.callParent(arguments);
263 // Ensure the field doesn't get submitted as part of any form
264 field.inputEl.dom.name = '';
265 if (me.swallowKeys) {
266 field.inputEl.swallowEvent([
267 'keypress', // *** Opera
268 'keydown' // *** all other browsers
274 onSpecialKey : function(field, event) {
276 key = event.getKey(),
277 complete = me.completeOnEnter && key == event.ENTER,
278 cancel = me.cancelOnEsc && key == event.ESC;
280 if (complete || cancel) {
282 // Must defer this slightly to prevent exiting edit mode before the field's own
283 // key nav can handle the enter key, e.g. selecting an item in a combobox list
284 Ext.defer(function() {
290 if (field.triggerBlur) {
296 this.fireEvent('specialkey', this, field, event);
299 <span id='Ext-Editor-method-startEdit'> /**
300 </span> * Starts the editing process and shows the editor.
301 * @param {Mixed} el The element to edit
302 * @param {String} value (optional) A value to initialize the editor with. If a value is not provided, it defaults
303 * to the innerHTML of el.
305 startEdit : function(el, value) {
310 me.boundEl = Ext.get(el);
311 value = Ext.isDefined(value) ? value : me.boundEl.dom.innerHTML;
314 me.render(me.parentEl || document.body);
317 if (me.fireEvent('beforestartedit', me, me.boundEl, value) !== false) {
318 me.startValue = value;
321 field.setValue(value);
323 field.focus(false, 10);
324 if (field.autoSize) {
331 <span id='Ext-Editor-method-realign'> /**
332 </span> * Realigns the editor to the bound field based on the current alignment config value.
333 * @param {Boolean} autoSize (optional) True to size the field to the dimensions of the bound element.
335 realign : function(autoSize) {
337 if (autoSize === true) {
338 me.doComponentLayout();
340 me.alignTo(me.boundEl, me.alignment, me.offsets);
343 <span id='Ext-Editor-method-completeEdit'> /**
344 </span> * Ends the editing process, persists the changed value to the underlying field, and hides the editor.
345 * @param {Boolean} remainVisible Override the default behavior and keep the editor visible after edit (defaults to false)
347 completeEdit : function(remainVisible) {
356 // Assert combo values first
357 if (field.assertValue) {
361 value = me.getValue();
362 if (!field.isValid()) {
363 if (me.revertInvalid !== false) {
364 me.cancelEdit(remainVisible);
369 if (String(value) === String(me.startValue) && me.ignoreNoChange) {
370 me.hideEdit(remainVisible);
374 if (me.fireEvent('beforecomplete', me, value, me.startValue) !== false) {
375 // Grab the value again, may have changed in beforecomplete
376 value = me.getValue();
377 if (me.updateEl && me.boundEl) {
378 me.boundEl.update(value);
380 me.hideEdit(remainVisible);
381 me.fireEvent('complete', me, value, me.startValue);
386 onShow : function() {
389 me.callParent(arguments);
390 if (me.hideEl !== false) {
393 me.fireEvent("startedit", me.boundEl, me.startValue);
396 <span id='Ext-Editor-method-cancelEdit'> /**
397 </span> * Cancels the editing process and hides the editor without persisting any changes. The field value will be
398 * reverted to the original starting value.
399 * @param {Boolean} remainVisible Override the default behavior and keep the editor visible after
400 * cancel (defaults to false)
402 cancelEdit : function(remainVisible) {
404 startValue = me.startValue,
408 value = me.getValue();
409 me.setValue(startValue);
410 me.hideEdit(remainVisible);
411 me.fireEvent('canceledit', me, value, startValue);
416 hideEdit: function(remainVisible) {
417 if (remainVisible !== true) {
418 this.editing = false;
424 onBlur : function() {
427 // selectSameEditor flag allows the same editor to be started without onBlur firing on itself
428 if(me.allowBlur === true && me.editing && me.selectSameEditor !== true) {
434 onHide : function() {
443 if (field.collapse) {
448 if (me.hideEl !== false) {
451 me.callParent(arguments);
454 <span id='Ext-Editor-method-setValue'> /**
455 </span> * Sets the data value of the editor
456 * @param {Mixed} value Any valid value supported by the underlying field
458 setValue : function(value) {
459 this.field.setValue(value);
462 <span id='Ext-Editor-method-getValue'> /**
463 </span> * Gets the data value of the editor
464 * @return {Mixed} The data value
466 getValue : function() {
467 return this.field.getValue();
470 beforeDestroy : function() {
473 Ext.destroy(me.field);
478 me.callParent(arguments);
480 });</pre></pre></body></html>