3 * Copyright(c) 2006-2009 Ext JS, LLC
5 * http://www.extjs.com/license
10 * @class Ext.ux.form.FileUploadField
11 * @extends Ext.form.TextField
12 * Creates a file upload field.
13 * @xtype fileuploadfield
15 Ext.ux.form.FileUploadField = Ext.extend(Ext.form.TextField, {
17 * @cfg {String} buttonText The button text to display on the upload button (defaults to
18 * 'Browse...'). Note that if you supply a value for {@link #buttonCfg}, the buttonCfg.text
19 * value will be used instead if available.
21 buttonText: 'Browse...',
23 * @cfg {Boolean} buttonOnly True to display the file upload field as a button with no visible
24 * text field (defaults to false). If true, all inherited TextField members will still be available.
28 * @cfg {Number} buttonOffset The number of pixels of space reserved between the button and the text field
29 * (defaults to 3). Note that this only applies if {@link #buttonOnly} = false.
33 * @cfg {Object} buttonCfg A standard {@link Ext.Button} config object.
43 autoSize: Ext.emptyFn,
46 initComponent: function(){
47 Ext.ux.form.FileUploadField.superclass.initComponent.call(this);
52 * Fires when the underlying file input field's value has changed from the user
53 * selecting a new file from the system file selection dialog.
54 * @param {Ext.ux.form.FileUploadField} this
55 * @param {String} value The file value returned by the underlying file input field
62 onRender : function(ct, position){
63 Ext.ux.form.FileUploadField.superclass.onRender.call(this, ct, position);
65 this.wrap = this.el.wrap({cls:'x-form-field-wrap x-form-file-wrap'});
66 this.el.addClass('x-form-file-text');
67 this.el.dom.removeAttribute('name');
69 this.fileInput = this.wrap.createChild({
70 id: this.getFileInputId(),
71 name: this.name||this.getId(),
78 var btnCfg = Ext.applyIf(this.buttonCfg || {}, {
81 this.button = new Ext.Button(Ext.apply(btnCfg, {
83 cls: 'x-form-file-btn' + (btnCfg.iconCls ? ' x-btn-icon' : '')
88 this.wrap.setWidth(this.button.getEl().getWidth());
91 this.fileInput.on('change', function(){
92 var v = this.fileInput.dom.value;
94 this.fireEvent('fileselected', this, v);
99 getFileInputId: function(){
100 return this.id + '-file';
104 onResize : function(w, h){
105 Ext.ux.form.FileUploadField.superclass.onResize.call(this, w, h);
107 this.wrap.setWidth(w);
109 if(!this.buttonOnly){
110 var w = this.wrap.getWidth() - this.button.getEl().getWidth() - this.buttonOffset;
116 onDestroy: function(){
117 Ext.ux.form.FileUploadField.superclass.onDestroy.call(this);
118 Ext.destroy(this.fileInput, this.button, this.wrap);
123 preFocus : Ext.emptyFn,
126 getResizeEl : function(){
131 getPositionEl : function(){
136 alignErrorIcon : function(){
137 this.errorIcon.alignTo(this.wrap, 'tl-tr', [2, 0]);
142 Ext.reg('fileuploadfield', Ext.ux.form.FileUploadField);
145 Ext.form.FileUploadField = Ext.ux.form.FileUploadField;