3 <title>The source code</title>
\r
4 <link href="../resources/prettify/prettify.css" type="text/css" rel="stylesheet" />
\r
5 <script type="text/javascript" src="../resources/prettify/prettify.js"></script>
\r
7 <body onload="prettyPrint();">
\r
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');
70 this.fileInput = this.wrap.createChild({
71 id: this.getFileInputId(),
72 name: this.name||this.getId(),
79 var btnCfg = Ext.applyIf(this.buttonCfg || {}, {
82 this.button = new Ext.Button(Ext.apply(btnCfg, {
84 cls: 'x-form-file-btn' + (btnCfg.iconCls ? ' x-btn-icon' : '')
89 this.wrap.setWidth(this.button.getEl().getWidth());
92 this.fileInput.on('change', function(){
93 var v = this.fileInput.dom.value;
95 this.fireEvent('fileselected', this, v);
100 getFileInputId: function(){
101 return this.id + '-file';
105 onResize : function(w, h){
106 Ext.ux.form.FileUploadField.superclass.onResize.call(this, w, h);
108 this.wrap.setWidth(w);
110 if(!this.buttonOnly){
111 var w = this.wrap.getWidth() - this.button.getEl().getWidth() - this.buttonOffset;
117 onDestroy: function(){
118 Ext.ux.form.FileUploadField.superclass.onDestroy.call(this);
119 Ext.destroy(this.fileInput, this.button, this.wrap);
124 preFocus : Ext.emptyFn,
127 getResizeEl : function(){
132 getPositionEl : function(){
137 alignErrorIcon : function(){
138 this.errorIcon.alignTo(this.wrap, 'tl-tr', [2, 0]);
143 Ext.reg('fileuploadfield', Ext.ux.form.FileUploadField);
146 Ext.form.FileUploadField = Ext.ux.form.FileUploadField;