Page 1 of 1
FileUpload widget : how to retreive the 1rst file name
Posted: Wed Jul 27, 2016 6:27 am
by k2R400
Hello,
There is a way to retreive by js, on the onchange event of a FileUpload Widget, the name of the first file selected ?
Thank you
Re: FileUpload widget : how to retreive the 1rst file name
Posted: Fri Jul 29, 2016 4:28 pm
by matt.denninghoff
Yes, it is possible. If you inspect what the FileUpload widget does to the DOM tree after you click "Select Files", you can see that a hidden <input> tag was added for each file you chose.
It looks like the FileUpload's onchange doesn't behave the same as with the simpler widgets; you can't reference "this.value". The onchange handler passes an argument to your code, but our obfuscator changes the name of the function argument. So for your code to work consistently between different versions of Profound, you'll need to use the special "arguments" array that is passed with every JavaScript function.
This code should get you started:
Code: Select all
var inputs=arguments[0].target.parentNode.parentNode.getElementsByTagName("input");
for(var i=0; i < inputs.length; i++){
console.log("i",i," value",inputs[i].value);
}
It simply outputs the values of each <input> tag to the console. There is always one extra input tag with no value--it gets a value after you select another file, and another input tag is created.
Also, it looks like the FileUpload widget only fires the onchange event after you click "Select Files"--clear and remove do not fire the event.
Re: FileUpload widget : how to retreive the 1rst file name
Posted: Sun Jul 31, 2016 3:44 am
by k2R400
Matt,
Thank you, good tricks