3
* Copyright(c) 2006-2008, Ext JS, LLC.
6
* http://extjs.com/license
11
* @extends Ext.Component
12
* A base editor field that handles displaying/hiding on demand and has some built-in sizing and event handling logic.
15
* @param {Ext.form.Field} field The Field object (or descendant)
16
* @param {Object} config The config object
18
Ext.Editor = function(field, config){
20
Ext.Editor.superclass.constructor.call(this, config);
23
Ext.extend(Ext.Editor, Ext.Component, {
25
* @cfg {Boolean/String} autoSize
26
* True for the editor to automatically adopt the size of the underlying field, "width" to adopt the width only,
27
* or "height" to adopt the height only (defaults to false)
30
* @cfg {Boolean} revertInvalid
31
* True to automatically revert the field value and cancel the edit when the user completes an edit and the field
32
* validation fails (defaults to true)
35
* @cfg {Boolean} ignoreNoChange
36
* True to skip the edit completion process (no save, no events fired) if the user completes an edit and
37
* the value has not changed (defaults to false). Applies only to string values - edits for other data types
38
* will never be ignored.
41
* @cfg {Boolean} hideEl
42
* False to keep the bound element visible while the editor is displayed (defaults to true)
46
* The data value of the underlying field (defaults to "")
50
* @cfg {String} alignment
51
* The position to align to (see {@link Ext.Element#alignTo} for more details, defaults to "c-c?").
55
* @cfg {Boolean/String} shadow "sides" for sides/bottom only, "frame" for 4-way shadow, and "drop"
56
* for bottom-right shadow (defaults to "frame")
60
* @cfg {Boolean} constrain True to constrain the editor to the viewport
64
* @cfg {Boolean} swallowKeys Handle the keydown/keypress events so they don't propagate (defaults to true)
68
* @cfg {Boolean} completeOnEnter True to complete the edit when the enter key is pressed (defaults to false)
70
completeOnEnter : false,
72
* @cfg {Boolean} cancelOnEsc True to cancel the edit when the escape key is pressed (defaults to false)
76
* @cfg {Boolean} updateEl True to update the innerHTML of the bound element when the update completes (defaults to false)
80
initComponent : function(){
81
Ext.Editor.superclass.initComponent.call(this);
84
* @event beforestartedit
85
* Fires when editing is initiated, but before the value changes. Editing can be canceled by returning
86
* false from the handler of this event.
87
* @param {Editor} this
88
* @param {Ext.Element} boundEl The underlying element bound to this editor
89
* @param {Mixed} value The field value being set
94
* Fires when this editor is displayed
95
* @param {Ext.Element} boundEl The underlying element bound to this editor
96
* @param {Mixed} value The starting field value
100
* @event beforecomplete
101
* Fires after a change has been made to the field, but before the change is reflected in the underlying
102
* field. Saving the change to the field can be canceled by returning false from the handler of this event.
103
* Note that if the value has not changed and ignoreNoChange = true, the editing will still end but this
104
* event will not fire since no edit actually occurred.
105
* @param {Editor} this
106
* @param {Mixed} value The current field value
107
* @param {Mixed} startValue The original field value
112
* Fires after editing is complete and any changed value has been written to the underlying field.
113
* @param {Editor} this
114
* @param {Mixed} value The current field value
115
* @param {Mixed} startValue The original field value
120
* Fires after editing has been canceled and the editor's value has been reset.
121
* @param {Editor} this
122
* @param {Mixed} value The user-entered field value that was discarded
123
* @param {Mixed} startValue The original field value that was set back into the editor after cancel
128
* Fires when any key related to navigation (arrows, tab, enter, esc, etc.) is pressed. You can check
129
* {@link Ext.EventObject#getKey} to determine which key was pressed.
130
* @param {Ext.form.Field} this
131
* @param {Ext.EventObject} e The event object
138
onRender : function(ct, position){
139
this.el = new Ext.Layer({
146
constrain: this.constrain
148
this.el.setStyle("overflow", Ext.isGecko ? "auto" : "hidden");
149
if(this.field.msgTarget != 'title'){
150
this.field.msgTarget = 'qtip';
152
this.field.inEditor = true;
153
this.field.render(this.el);
155
this.field.el.dom.setAttribute('autocomplete', 'off');
157
this.field.on("specialkey", this.onSpecialKey, this);
158
if(this.swallowKeys){
159
this.field.el.swallowEvent(['keydown','keypress']);
162
this.field.on("blur", this.onBlur, this);
164
this.field.on("autosize", this.el.sync, this.el, {delay:1});
169
onSpecialKey : function(field, e){
170
var key = e.getKey();
171
if(this.completeOnEnter && key == e.ENTER){
174
}else if(this.cancelOnEsc && key == e.ESC){
177
this.fireEvent('specialkey', field, e);
179
if(this.field.triggerBlur && (key == e.ENTER || key == e.ESC || key == e.TAB)){
180
this.field.triggerBlur();
185
* Starts the editing process and shows the editor.
186
* @param {Mixed} el The element to edit
187
* @param {String} value (optional) A value to initialize the editor with. If a value is not provided, it defaults
188
* to the innerHTML of el.
190
startEdit : function(el, value){
194
this.boundEl = Ext.get(el);
195
var v = value !== undefined ? value : this.boundEl.dom.innerHTML;
197
this.render(this.parentEl || document.body);
199
if(this.fireEvent("beforestartedit", this, this.boundEl, v) === false){
203
this.field.setValue(v);
205
this.el.alignTo(this.boundEl, this.alignment);
211
doAutoSize : function(){
213
var sz = this.boundEl.getSize();
214
switch(this.autoSize){
216
this.setSize(sz.width, "");
219
this.setSize("", sz.height);
222
this.setSize(sz.width, sz.height);
228
* Sets the height and width of this editor.
229
* @param {Number} width The new width
230
* @param {Number} height The new height
232
setSize : function(w, h){
233
delete this.field.lastSize;
234
this.field.setSize(w, h);
236
if(Ext.isGecko2 || Ext.isOpera){
237
// prevent layer scrollbars
238
this.el.setSize(w, h);
245
* Realigns the editor to the bound field based on the current alignment config value.
247
realign : function(){
248
this.el.alignTo(this.boundEl, this.alignment);
252
* Ends the editing process, persists the changed value to the underlying field, and hides the editor.
253
* @param {Boolean} remainVisible Override the default behavior and keep the editor visible after edit (defaults to false)
255
completeEdit : function(remainVisible){
259
var v = this.getValue();
260
if(this.revertInvalid !== false && !this.field.isValid()){
262
this.cancelEdit(true);
264
if(String(v) === String(this.startValue) && this.ignoreNoChange){
265
this.editing = false;
269
if(this.fireEvent("beforecomplete", this, v, this.startValue) !== false){
270
this.editing = false;
271
if(this.updateEl && this.boundEl){
272
this.boundEl.update(v);
274
if(remainVisible !== true){
277
this.fireEvent("complete", this, v, this.startValue);
284
if(this.hideEl !== false){
288
if(Ext.isIE && !this.fixIEFocus){ // IE has problems with focusing the first time
289
this.fixIEFocus = true;
290
this.deferredFocus.defer(50, this);
294
this.fireEvent("startedit", this.boundEl, this.startValue);
297
deferredFocus : function(){
304
* Cancels the editing process and hides the editor without persisting any changes. The field value will be
305
* reverted to the original starting value.
306
* @param {Boolean} remainVisible Override the default behavior and keep the editor visible after
307
* cancel (defaults to false)
309
cancelEdit : function(remainVisible){
311
var v = this.getValue();
312
this.setValue(this.startValue);
313
if(remainVisible !== true){
316
this.fireEvent("canceledit", this, v, this.startValue);
322
if(this.allowBlur !== true && this.editing){
334
if(this.field.collapse){
335
this.field.collapse();
338
if(this.hideEl !== false){
344
* Sets the data value of the editor
345
* @param {Mixed} value Any valid value supported by the underlying field
347
setValue : function(v){
348
this.field.setValue(v);
352
* Gets the data value of the editor
353
* @return {Mixed} The data value
355
getValue : function(){
356
return this.field.getValue();
359
beforeDestroy : function(){
360
this.field.destroy();
364
Ext.reg('editor', Ext.Editor);
b'\\ No newline at end of file'