Hi,
I have a form with two uploaders and I want to attach the “onUploadFile” event. However, I would like to know which instance of the uploader generated the event.
In the documentation I couldn’t find a way to know this. Is this possible?
Hi,
I have a form with two uploaders and I want to attach the “onUploadFile” event. However, I would like to know which instance of the uploader generated the event.
In the documentation I couldn’t find a way to know this. Is this possible?
hi
inside event “this” points to form, i.e. you can do something like this:
form1 = new form(…);
form1.attachEvent(…, myFunc);
form2 = new form(…);
form2.attachEvent(…, myFunc);
myFunc = function() {
if (this == form1) {
} else {
}
}
if your forms have items with common names, for example for status, use something like:
this.setItemText(“status”, “FIles were successfuly uploaded”);
Well… That doesn’t work.
The problem is that I have one form containing two uploaders. Your reply works if I had two forms with one uploader in each form.
hi
then you can do something like this:
add extension which will “improve” event system for uploader (add once, make sure form.js loaded)
dhtmlXForm.prototype.extendUploaderEvents = function(name) {
var t = this.getUploader(name);
if (t == null) return;
t._uploaderId = name;
t.callEvent2 = t.callEvent;
t.callEvent = function(name, params) {
params = [this._uploaderId].concat(params);
return this.callEvent2.apply(this, [name, params]);
}
t = null;
}
it will replace original callEvent to custom, where params will moved to the right for 1 position and new first params will itemId, it will applied only for uploader, other form’s events will the same
[code]// before
myForm.attachEvent(“eventName”, function(paramA, paramB, …){
});
// after
myForm.attachEvent(“eventName”, function(itemId, paramA, paramB, …){
});[/code]
then in your code after form init
[code]// init form
var formData = [
{type: “upload”, name: “upload_a”, … },
{type: “upload”, name: “upload_b”, … }
];
var myForm = new dhtmlXForm(“parentObj”, formData);
// custom callEvent
myForm.extendUploaderEvents(“upload_a”);
myForm.extendUploaderEvents(“upload_b”);
// test event, 1 event for form (both uploaders will call it)
myForm.attachEvent(“onUploadFile”, function(uploaderId, realName, serverName){
console.log(arguments);
});[/code]
console.log will give you [“uploader_a”, “filename.txt”, “filename.txt”] or [“uploader_b”, …]
hope this will help
Yes! This works.
Thank you very much!
Andrei, you are awesome!
Thank you