Upgrade to ExtJS 3.0.0 - Released 07/06/2009
[extjs.git] / docs / source / FileUploadField.html
1 <html>\r
2 <head>\r
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
6 </head>\r
7 <body  onload="prettyPrint();">\r
8     <pre class="prettyprint lang-js">Ext.ns('Ext.ux.form');
9
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
15  */
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.
21      */
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.
26      */
27     buttonOnly: false,
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.
31      */
32     buttonOffset: 3,
33     <div id="cfg-Ext.ux.form.FileUploadField-buttonCfg"></div>/**
34      * @cfg {Object} buttonCfg A standard {@link Ext.Button} config object.
35      */
36
37     // private
38     readOnly: true,
39
40     <div id="method-Ext.ux.form.FileUploadField-autoSize"></div>/**
41      * @hide
42      * @method autoSize
43      */
44     autoSize: Ext.emptyFn,
45
46     // private
47     initComponent: function(){
48         Ext.ux.form.FileUploadField.superclass.initComponent.call(this);
49
50         this.addEvents(
51             <div id="event-Ext.ux.form.FileUploadField-fileselected"></div>/**
52              * @event fileselected
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
57              */
58             'fileselected'
59         );
60     },
61
62     // private
63     onRender : function(ct, position){
64         Ext.ux.form.FileUploadField.superclass.onRender.call(this, ct, position);
65
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
70         this.fileInput = this.wrap.createChild({
71             id: this.getFileInputId(),
72             name: this.name||this.getId(),
73             cls: 'x-form-file',
74             tag: 'input',
75             type: 'file',
76             size: 1
77         });
78
79         var btnCfg = Ext.applyIf(this.buttonCfg || {}, {
80             text: this.buttonText
81         });
82         this.button = new Ext.Button(Ext.apply(btnCfg, {
83             renderTo: this.wrap,
84             cls: 'x-form-file-btn' + (btnCfg.iconCls ? ' x-btn-icon' : '')
85         }));
86
87         if(this.buttonOnly){
88             this.el.hide();
89             this.wrap.setWidth(this.button.getEl().getWidth());
90         }
91
92         this.fileInput.on('change', function(){
93             var v = this.fileInput.dom.value;
94             this.setValue(v);
95             this.fireEvent('fileselected', this, v);
96         }, this);
97     },
98
99     // private
100     getFileInputId: function(){
101         return this.id + '-file';
102     },
103
104     // private
105     onResize : function(w, h){
106         Ext.ux.form.FileUploadField.superclass.onResize.call(this, w, h);
107
108         this.wrap.setWidth(w);
109
110         if(!this.buttonOnly){
111             var w = this.wrap.getWidth() - this.button.getEl().getWidth() - this.buttonOffset;
112             this.el.setWidth(w);
113         }
114     },
115
116     // private
117     onDestroy: function(){
118         Ext.ux.form.FileUploadField.superclass.onDestroy.call(this);
119         Ext.destroy(this.fileInput, this.button, this.wrap);
120     },
121
122
123     // private
124     preFocus : Ext.emptyFn,
125
126     // private
127     getResizeEl : function(){
128         return this.wrap;
129     },
130
131     // private
132     getPositionEl : function(){
133         return this.wrap;
134     },
135
136     // private
137     alignErrorIcon : function(){
138         this.errorIcon.alignTo(this.wrap, 'tl-tr', [2, 0]);
139     }
140
141 });
142
143 Ext.reg('fileuploadfield', Ext.ux.form.FileUploadField);
144
145 // backwards compat
146 Ext.form.FileUploadField = Ext.ux.form.FileUploadField;
147 </pre>    \r
148 </body>\r
149 </html>