1. For uploading files we use a dynamic form, the UploadItem and a ComboBoxItem are both marked as required.
This works just beautifully.
2. However, if I do not select a file to upload, then press submit button, I of course get the field is required error on the UploadItem.
3. I then click the browse button, and select a file to upload.
4. I press the submit button , after the form is validated but before it is submitted, I call a server side datasource to check some data
which is unrelated to the file to upload, but after the call to that datasource, the file name is nulled out in the form.
5. My question is how can I clear the error state of the UploadItem, such that when I do select a file, its value is not lost when the form is submitted?
And further, why is the value of the File selected lost, and how can I work around this while keeping the UploadItem required.
6. This behaviour is not browser dependant, it happens on IE, FF, and Safari.
Looking at the forums I see that UploadItems are a bit touchy.
Any help you could give me would be greatly appreciated.
This works just beautifully.
2. However, if I do not select a file to upload, then press submit button, I of course get the field is required error on the UploadItem.
3. I then click the browse button, and select a file to upload.
4. I press the submit button , after the form is validated but before it is submitted, I call a server side datasource to check some data
which is unrelated to the file to upload, but after the call to that datasource, the file name is nulled out in the form.
5. My question is how can I clear the error state of the UploadItem, such that when I do select a file, its value is not lost when the form is submitted?
And further, why is the value of the File selected lost, and how can I work around this while keeping the UploadItem required.
6. This behaviour is not browser dependant, it happens on IE, FF, and Safari.
Looking at the forums I see that UploadItems are a bit touchy.
Any help you could give me would be greatly appreciated.
Code:
1. For uploading files we use a dynamic form, the UploadItem and a ComboBoxItem are both marked as required.
This works just beautifully. There is a custom validator on the UploadItem, in IE you can type into the upload item text box, and we are checking
against certain entries.
2. However, if I do not select a file to upload, then press submit button, I of course get the field is required error on the UploadItem.
3. I then click the browse button, and select a file to upload.
4. I press the submit button , but somewhere prior to the form being submitted the value of the UploadItem is nulled out on me.
I include the code below, see highlights in red, after form is validated but before it is submitted, I call a server side datasource to check some data
which is unrelated to the file to upload, but after the call to the datasource, the file name is nulled out in the form.
5. My question is how can I clear the error state of the UploadItem, such that when I do select a file, its value is not lost when the form is submitted?
And further, why is the value of the File selected lost, and how can I work around this while keeping the UploadItem required.
6. This behaviour is not browser dependant, it happens on IE, FF, and Safari.
Looking at the forums I see that UploadItems are a bit touchy.
Any help you could give me would be greatly appreciated.
Cheers,
Nick Mogielnicki
Here is the pertinent DynamicForm code and related functions:
=================================================================================================================
var uploadForm = isc.DynamicForm.create({
name:"uploadForm",
encoding:"multipart",
action:"MyFGUpload.do",
canSubmit:true,
autoFetchData:false,
target:"hiddenIframeForUpload",
show: function () {
uploadForm.getField("UploadPath").fetchData();
this.Super("show", arguments);
},
fields:[
{
name:"UploadPath",
title:"Upload Path",
required:true,
autoFetchData:false,
_constructor:"ComboBoxItem",
optionDataSource:upload_DS,
showOptionsFromDataSource:true
},
{
name:"FileName",
title:"File",
required:true,
_constructor:"UploadItem",
}]
},
{
name:"SubmitButton",
title:"Send",
_constructor:"Button",
click:function () {
sendFile();
}
}
],
});
var sendFile = function () {
var thisUploadPath = myFgForm.getField("UploadPath").getValue();
// need this to get Safari 4.0.4 to work
uploadForm .getItem("FileName").updateValue();
// we have the value of the file selected.....
alert ('sendFile, upload file = ' + uploadForm .getField("FileName").getValue());
if (uploadForm.validate()) {
// we have the value of file selected.....
alert ('sendFile, form is valid, file = ' + uploadForm .getField("FileName").getValue());
// save off the file name so I can re-set it after it gets nulled out mysteriously ?
var file = myFgForm.getField("FileName").getValue();
// call server side data source
uploadMonitored_DS.fetchData({uploadPath:thisUploadPath}, function (dsResponse, data, dsRequest) {
// AT THIS POINT THE VALUE OF THE FILE NAME IN THE FORM IS NULL!
myFgMonitoredUploadFlag.setValue(data.monitored);
// NULL IS RETURNED IN THE getValue code
alert ('sendFile, after uploadMonitored_DS.fetchData call, file = ' + uploadForm.getField("FileName").getValue());
// TRYING TO RESET THE VALUE OF THE FILE NAME IN THE FORM - DOES NOT WORK!
uploadForm.getField("FileName").setValue(file);
uploadForm.getItem("FileName").updateValue();
// even after trying to reset the file name in the form, FileName is NULL
alert ('sendFile, after resetting the file value in the form, file = ' + uploadForm.getField("FileName").getValue());
processMonitoredUpload(value);
}
);
}
}
function processMonitoredUpload(value) {
if (value) {
// FileName is NULL
alert ('processMonitoredUpload, upload file = ' + uploadForm.getField("FileName").getValue());
var thisFileName = uploadForm.getField("FileName").getValue();
var thisUploadPath = uploadForm.getField("UploadPath").getValue();
fileUploadValidation_DS.fetchData(
{uploadPath:thisUploadPath, fileName:thisFileName, renameMessage: thisRenameMessage},
function (dsResponse, data, dsRequest) { processUploadValidataion(dsResponse, data, dsRequest) }
);
}
}
function processUploadValidataion(dsReponse, data, dsRequest) {
// FileName is NULL - null pointer ensues on the server side
alert ('processUploadValidataion, upload file = ' + uploadForm.getField("FileName").getValue());
uploadForm.submit();
return;
}
Comment