3 <title>The source code</title>
4 <link href="../resources/prettify/prettify.css" type="text/css" rel="stylesheet" />
5 <script type="text/javascript" src="../resources/prettify/prettify.js"></script>
7 <body onload="prettyPrint();">
8 <pre class="prettyprint lang-js">Ext.ns('Ext.ux.form');
10 <div id="cls-Ext.ux.form.FileUploadField"></div>/**
11 * @class Ext.ux.form.FileUploadField
12 * @extends Ext.form.TextField
13 * Creates a file upload field.
14 * @xtype fileuploadfield
16 Ext.ux.form.FileUploadField = Ext.extend(Ext.form.TextField, {
17 <div id="cfg-Ext.ux.form.FileUploadField-buttonText"></div>/**
18 * @cfg {String} buttonText The button text to display on the upload button (defaults to
19 * 'Browse...'). Note that if you supply a value for {@link #buttonCfg}, the buttonCfg.text
20 * value will be used instead if available.
22 buttonText: 'Browse...',
23 <div id="cfg-Ext.ux.form.FileUploadField-buttonOnly"></div>/**
24 * @cfg {Boolean} buttonOnly True to display the file upload field as a button with no visible
25 * text field (defaults to false). If true, all inherited TextField members will still be available.
28 <div id="cfg-Ext.ux.form.FileUploadField-buttonOffset"></div>/**
29 * @cfg {Number} buttonOffset The number of pixels of space reserved between the button and the text field
30 * (defaults to 3). Note that this only applies if {@link #buttonOnly} = false.
33 <div id="cfg-Ext.ux.form.FileUploadField-buttonCfg"></div>/**
34 * @cfg {Object} buttonCfg A standard {@link Ext.Button} config object.
40 <div id="method-Ext.ux.form.FileUploadField-autoSize"></div>/**
44 autoSize: Ext.emptyFn,
47 initComponent: function(){
48 Ext.ux.form.FileUploadField.superclass.initComponent.call(this);
51 <div id="event-Ext.ux.form.FileUploadField-fileselected"></div>/**
53 * Fires when the underlying file input field's value has changed from the user
54 * selecting a new file from the system file selection dialog.
55 * @param {Ext.ux.form.FileUploadField} this
56 * @param {String} value The file value returned by the underlying file input field
63 onRender : function(ct, position){
64 Ext.ux.form.FileUploadField.superclass.onRender.call(this, ct, position);
66 this.wrap = this.el.wrap({cls:'x-form-field-wrap x-form-file-wrap'});
67 this.el.addClass('x-form-file-text');
68 this.el.dom.removeAttribute('name');
69 this.createFileInput();
71 var btnCfg = Ext.applyIf(this.buttonCfg || {}, {
74 this.button = new Ext.Button(Ext.apply(btnCfg, {
76 cls: 'x-form-file-btn' + (btnCfg.iconCls ? ' x-btn-icon' : '')
81 this.wrap.setWidth(this.button.getEl().getWidth());
85 this.resizeEl = this.positionEl = this.wrap;
88 bindListeners: function(){
91 mouseenter: function() {
92 this.button.addClass(['x-btn-over','x-btn-focus'])
94 mouseleave: function(){
95 this.button.removeClass(['x-btn-over','x-btn-focus','x-btn-click'])
97 mousedown: function(){
98 this.button.addClass('x-btn-click')
101 this.button.removeClass(['x-btn-over','x-btn-focus','x-btn-click'])
104 var v = this.fileInput.dom.value;
106 this.fireEvent('fileselected', this, v);
111 createFileInput : function() {
112 this.fileInput = this.wrap.createChild({
113 id: this.getFileInputId(),
114 name: this.name||this.getId(),
123 this.fileInput.remove();
124 this.createFileInput();
125 this.bindListeners();
126 Ext.ux.form.FileUploadField.superclass.reset.call(this);
130 getFileInputId: function(){
131 return this.id + '-file';
135 onResize : function(w, h){
136 Ext.ux.form.FileUploadField.superclass.onResize.call(this, w, h);
138 this.wrap.setWidth(w);
140 if(!this.buttonOnly){
141 var w = this.wrap.getWidth() - this.button.getEl().getWidth() - this.buttonOffset;
147 onDestroy: function(){
148 Ext.ux.form.FileUploadField.superclass.onDestroy.call(this);
149 Ext.destroy(this.fileInput, this.button, this.wrap);
152 onDisable: function(){
153 Ext.ux.form.FileUploadField.superclass.onDisable.call(this);
154 this.doDisable(true);
157 onEnable: function(){
158 Ext.ux.form.FileUploadField.superclass.onEnable.call(this);
159 this.doDisable(false);
164 doDisable: function(disabled){
165 this.fileInput.dom.disabled = disabled;
166 this.button.setDisabled(disabled);
171 preFocus : Ext.emptyFn,
174 alignErrorIcon : function(){
175 this.errorIcon.alignTo(this.wrap, 'tl-tr', [2, 0]);
180 Ext.reg('fileuploadfield', Ext.ux.form.FileUploadField);
183 Ext.form.FileUploadField = Ext.ux.form.FileUploadField;