2 * Ext JS Library 2.2.1
\r
3 * Copyright(c) 2006-2009, Ext JS, LLC.
\r
4 * licensing@extjs.com
\r
6 * http://extjs.com/license
\r
10 Ext.form.FileUploadField = Ext.extend(Ext.form.TextField, {
\r
12 * @cfg {String} buttonText The button text to display on the upload button (defaults to
\r
13 * 'Browse...'). Note that if you supply a value for {@link #buttonCfg}, the buttonCfg.text
\r
14 * value will be used instead if available.
\r
16 buttonText: 'Browse...',
\r
18 * @cfg {Boolean} buttonOnly True to display the file upload field as a button with no visible
\r
19 * text field (defaults to false). If true, all inherited TextField members will still be available.
\r
23 * @cfg {Number} buttonOffset The number of pixels of space reserved between the button and the text field
\r
24 * (defaults to 3). Note that this only applies if {@link #buttonOnly} = false.
\r
28 * @cfg {Object} buttonCfg A standard {@link Ext.Button} config object.
\r
38 autoSize: Ext.emptyFn,
\r
41 initComponent: function(){
\r
42 Ext.form.FileUploadField.superclass.initComponent.call(this);
\r
46 * @event fileselected
\r
47 * Fires when the underlying file input field's value has changed from the user
\r
48 * selecting a new file from the system file selection dialog.
\r
49 * @param {Ext.form.FileUploadField} this
\r
50 * @param {String} value The file value returned by the underlying file input field
\r
57 onRender : function(ct, position){
\r
58 Ext.form.FileUploadField.superclass.onRender.call(this, ct, position);
\r
60 this.wrap = this.el.wrap({cls:'x-form-field-wrap x-form-file-wrap'});
\r
61 this.el.addClass('x-form-file-text');
\r
62 this.el.dom.removeAttribute('name');
\r
64 this.fileInput = this.wrap.createChild({
\r
65 id: this.getFileInputId(),
\r
66 name: this.name||this.getId(),
\r
73 var btnCfg = Ext.applyIf(this.buttonCfg || {}, {
\r
74 text: this.buttonText
\r
76 this.button = new Ext.Button(Ext.apply(btnCfg, {
\r
77 renderTo: this.wrap,
\r
78 cls: 'x-form-file-btn' + (btnCfg.iconCls ? ' x-btn-icon' : '')
\r
81 if(this.buttonOnly){
\r
83 this.wrap.setWidth(this.button.getEl().getWidth());
\r
86 this.fileInput.on('change', function(){
\r
87 var v = this.fileInput.dom.value;
\r
89 this.fireEvent('fileselected', this, v);
\r
94 getFileInputId: function(){
\r
95 return this.id+'-file';
\r
99 onResize : function(w, h){
\r
100 Ext.form.FileUploadField.superclass.onResize.call(this, w, h);
\r
102 this.wrap.setWidth(w);
\r
104 if(!this.buttonOnly){
\r
105 var w = this.wrap.getWidth() - this.button.getEl().getWidth() - this.buttonOffset;
\r
106 this.el.setWidth(w);
\r
111 preFocus : Ext.emptyFn,
\r
114 getResizeEl : function(){
\r
119 getPositionEl : function(){
\r
124 alignErrorIcon : function(){
\r
125 this.errorIcon.alignTo(this.wrap, 'tl-tr', [2, 0]);
\r
129 Ext.reg('fileuploadfield', Ext.form.FileUploadField);