EXTJS themed file input field
Author: gaweee | Filed under: UncategorizedTheming a file input field has always been notoriously hard. Thanks to the guys who wrote the Ext UploadDialog script, theres now a better and more aesthetically pleasing way to create a file upload. I tried using their script wholesale but ran into some problems with the layout. So i kinda hacked and extracted their Ext.ux.BrowseButton code.
So now you can use it simply with:
new Ext.ux.BrowseButton({
input_name: "uploadfile1",
text: "Select a file"
onInputFileChange: function() {
alert("you chose " + this.getInputFile().dom.value);
}
})
new Ext.ux.TBBrowseButton({
input_name: "uploadfile2",
text: "Select another file"
})The first chunk of code creates a Browse Button (File Input) control as with the name uploadfile1. and the second chunk of codes creates a ToolBar Browse Button with the name uploadfile2.
Hypothetically you should be able to add a ToolBar button but i havent quite gotten a ToolBar Browse Button to fit aesthetically well inside a form. Let me know if you all come up with any examples that do!
Meanwhile, 3 cheers for the guys who wrote the Ext UploadDialog script!!!
Download the jQuery progressbar here: EXT Browse Button
or view the demo here
I encountered a interesting display bug when working with EXTJS recently. The following code renders well in FF 2 and above but not in IE6.
var form = new Ext.form.FormPanel({
baseCls: 'x-plain',
labelWidth: 140,
url: 'abc/def.php',
defaultType: 'textfield',
items: [{
fieldLabel: 'Name',
name: 'name',
anchor:'100%' // anchor width by percentage
}, {
xtype: 'textarea',
fieldLabel: 'Description',
name: 'description',
anchor: '100% -30' // bug in IE6
}]
});
var window = new Ext.Window({
title: 'Some Window',
width: 500, height: 300,
layout: 'fit',
plain: true,
buttonAlign: 'center',
items: form
});
window.show();brian.moeskau from the EXTJS forums was kind enough to answer this problem. The fix is a piece of code that primes the width of the controls to prevent it from overflowing out of the window/panels. The code is as follows
Ext.override(Ext.form.Field, {
adjustWidth : function(tag, w){
tag = tag.toLowerCase();
if(typeof w == 'number' && !Ext.isSafari){
if(Ext.isIE && (tag == 'input' || tag == 'textarea')){
if(!Ext.isStrict){
return this.inEditor ? w : w - 3;
}
if(tag == 'input' && Ext.isStrict){
return w - (Ext.isIE6 ? 4 : 1);
}
if(tag == 'textarea' && Ext.isStrict){
return w-4;
}
}else if(Ext.isOpera && Ext.isStrict){
if(tag == 'input'){
return w + 2;
}
if(tag == 'textarea'){
return w-2;
}
}
}
return w;
}
});I hope this will solve other people’s problems too!
Most Popular
- HOWTO: PHP and jQuery upload progress bar (47)
- JQuery Progress Bar 1.1 (41)
- Howto: Repackageable custom extension development in Magento - Part 2 - Admin Controller (24)
- Howto: Repackageable custom extension development in Magento - Part 8 - CRUD - Update (13)
- HOWTO: struts 2 i18n (12)
- JQuery Progress Bar 2.0 (11)
- JQuery Progress Bar 1.2 (10)
- Howto: Repackageable custom extension development in Magento - Part 3 - Database (9)
- Howto: Repackageable custom extension development in Magento (8)
- Howto: Repackageable custom extension development in Magento - Part 5 - CRUD - Retrieve (6)
Recent Comments
- donald: Hi Wen, I have checked out
- donald: Hi Ashley, Currently, I simply use
- donald: Hi Noemi, there are many
- Serge: Thanks a lot. It's the simplest
- Zoran: Excellent posts you got here...
- Craig: Brilliant tutorial! There's NOTHING on
- Will: Thnak you! I was
- Margots: Thank you a lot for
- Aswin S: Wow great dude.. For the
- Noemi Heier: This is great! How did
Latest Entries
- jQuery Progress Bar Configuration
- Extracting email addresses from inbox
- 10 Good (Free and Legal) Source for Photos and Images
- Howto: Backup Microsoft SQL Server Database, as in Dump it to a SQL Script (like MYSQL's sqldump)
- Managing client's expectation with wireframe software
- Howto: Repackageable custom extension development in Magento - Part 9 - Frontend - List
- JQuery Progress Bar 2.0
- HOWTO: Find icons for your new prototype system
- Google Maps Helper
- laying the cornerstones