PDA

View Full Version : Upload window does not render correctly on second time



TheBigOnion
20 Jul 2010, 12:06 PM
Ok, sorry. I had an old version of my code listed here so there was some confusion. Please take a look at the updated code and my problem. Thank you very much for any help here.


Hello all,
I have been working with some sample code for doing an upload. The little window looks great on the first time, but the second time I try to launch the little window, the upload textbox does not allow the user to choose a file. (well, they can choose it, but it does not appear in the upload textbox) Here is a screen shot.

21541


I cannot figure out why it is acting this way. Here is my code: (some of the page is missing, but I have included the important parts)




/* --- Begin Functions --- */
function do_buttons() {
var row = Ext.grid_control.getSelectionModel().getSelected();

if (row != null) {
Ext.getCmp('download_button').enable();
} else {
Ext.getCmp('download_button').disable();
}
}




Ext.upload_Fields = {
xtype: 'fieldset'
,title: 'upload data'
//,height: 300
,autoWidth: true
,autoHeight: true
,border: true
,layout: 'form'
,labelWidth: 100
,defaultType: 'textfield'
,defaults: {
anchor: '-20'
,allowBlank: false
}
,items: [
{
fieldLabel: 'Keyword'
,name: 'keyword'
,allowBlank:false
}
]
};

Ext.upload_form = new Ext.FormPanel({
fileUpload: true,
width: 420,
frame: true,
autoheight:true,
bodyStyle: 'padding: 10px 10px 0 5px;',
labelWidth: 60,
defaults: {
anchor: '90%',
msgTarget: 'side',
allowBlank: false
},
items: [
{
xtype: 'fileuploadfield'
,id: 'form-file'
,emptyText: 'Select a file'
,fieldLabel: 'File'
,name: 'Filecontent'
,buttonCfg: {
text: '',
iconCls: 'upload-icon'
}
,x: 15
,width: 150
},
{
xtype: 'label'
,id: 'fieldDivider'
,html: "<br><br>"
},
Ext.upload_Fields

]
});

Ext.upload_window = new Ext.Window({
title:'Form Upload',
width:430,
autoHeight: true,
closable: true,
resizable:false,
items: [Ext.upload_form],
buttons: [{
text: 'Upload',
handler: function(){
if(Ext.upload_form.getForm().isValid()){
Ext.upload_form.getForm().submit({
url: 'upload.php',
params: {uploadPath: Ext.current_directory},
waitMsg: 'Uploading your file...',
success: function(fp, o){
Ext.MessageBox.alert('Upload','Upload Complete.');
Ext.grid.ds.reload({
callback: do_buttons
});
Ext.upload_window.hide();
Ext.upload_form.getForm().reset();
},
failure: function(fp, o){
Ext.MessageBox.alert('Warning','try again,data failure.');
}
});
}
}
},{
text: 'Cancel',
handler: function() {
Ext.upload_window.hide();
Ext.upload_form.getForm().reset();
}}]
});


function do_upload() {

Ext.upload_window.show();
}

/* --- End Functions --- */


I would really appreciate it if someone could help me figure out this problem.

Thanks.

Animal
20 Jul 2010, 12:15 PM
Come on, think about it.

Every time they click the button you want to create the input fields and the Window? Every time?

TheBigOnion
21 Jul 2010, 3:28 AM
?

TheBigOnion
4 Oct 2010, 1:08 PM
bump

Animal
4 Oct 2010, 10:40 PM
Bump what? The answer is in post 2. Read your code. You are duplicating everything every time!

Condor
5 Oct 2010, 1:06 AM
As Animal said, it's probably better to only hide (closeAction:'hide') the window and reuse it instead of creating a new one every time.

But if you want to keep destroying and recreating the window, then you should at least close() the window and not hide() it in the Cancel button handler.

TheBigOnion
5 Oct 2010, 3:40 AM
Condor.
Where am I destroying my form?

steffenk
5 Oct 2010, 3:46 AM
so difficult?
Without closeAction defined any action does a close() and this destroys the window.
(Check your code: you hide only on cancel, but create a new instance all the time)
As Animal and Condor already said: define the window once, set closeAction to hide and reuse it anytime you need.