FileUpload widget : how to retreive the 1rst file name

Use this board to ask questions or have discussions with other Rich Displays users.
Post Reply
k2R400
Profound User
Posts: 62
Joined: Sat Feb 18, 2012 12:03 pm
First Name: Patrick
Last Name: THOMAS
Company Name: Oo2
Country: France
Contact:

FileUpload widget : how to retreive the 1rst file name

Post 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
User avatar
matt.denninghoff
Profound Logic Staff Member
Posts: 115
Joined: Wed Feb 10, 2016 3:53 pm
First Name: Matthew
Last Name: Denninghoff
Company Name: Profound Logic Software
State / Province: Ohio
Country: United States
Contact:

Re: FileUpload widget : how to retreive the 1rst file name

Post 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.
k2R400
Profound User
Posts: 62
Joined: Sat Feb 18, 2012 12:03 pm
First Name: Patrick
Last Name: THOMAS
Company Name: Oo2
Country: France
Contact:

Re: FileUpload widget : how to retreive the 1rst file name

Post by k2R400 »

Matt,

Thank you, good tricks
Post Reply

Who is online

Users browsing this forum: No registered users and 3 guests