Jump to content

Recommended Posts

Hello @CoopperBackpack

You may use additional JS code to implement this workflow:

<script type="text/javascript">
document.addEventListener('DataPageReady', fileInputEvent)

function fileInputEvent() {
 document.querySelector("#InsertRecordFile_f"),addEventListener('change', fileInputHandler); // use the InsertRecord[your file field name] instead
 document.removeEventListener('DataPageReady', fileInputEvent)
}

function fileInputHandler(event) {
 const fileSizeInput = document.querySelector('#InsertRecordFile_size'); // use the InsertRecord[your file size field name] instead
 fileSizeInput.value = event.target.files[0].size;
}
</script>

Insert this code into the header of the submission form. Do not forget to disable the HTML editor.

For the file size field use the Number data type. You also may make the size field hidden in the submission form.

Link to post
Share on other sites
  • 2 weeks later...

Hi @jrifkin,

It is possible but you need to follow certain naming convention:

1. Files fields you need to name them as:  File_1, FIle_2, File_3 ...

2. File size fields should be named as: File_1_size, File_2_size, File_3_size ...

Here is a slightly modified JavaScript provided by @Hastur:

<script>
  
document.addEventListener('DataPageReady', fileInputEvent)

function fileInputEvent() {

 const fileFields = ['File_1', 'File_2']; //add more file fields if needed
 

 fileFields.forEach(el=>{
   document.querySelector(`#InsertRecord${el}`).addEventListener('change', fileInputHandler);
 });

 document.removeEventListener('DataPageReady', fileInputEvent)
}

function fileInputHandler(event) {

 
 const fileSizeInput = document.querySelector(`#${event.target.name}_size`); 
 fileSizeInput.value = event.target.files[0].size;
}

</script>

You may change InsertRecord prefix to EditRecord in order to use this JavaScript in Details/Update Datapages.

Hope this helps.

Regards,

vitalikssssss

 

Link to post
Share on other sites

You are absolutely awesome! This is my first time using the community forum and I am so appreciative for the help! You all are so awesome! One last question, if I wanted to also get the file extension stored in a cell, like .txt or .pdf how would I do that? 

 

 

would I do:

 

const fileSizeInput = document.querySelector(`#${event.target.name}_size`);

fileSizeInput.value = event.target.files[0].size;

--and add below--

const fileExtensionInput = document.querySelector(`#${event.target.name}_extension`);

fileExtensionInput.value = event.target.files[0].extension (or whatever the appr. termonology is?;

Link to post
Share on other sites

Hi @jrifkin,

Glad that heard that solution has helped.

Here is updated version which would also capture the file extension.

Please note that you should use the following naming convention for your fields which would store extension: File_1_ext  File_2_ext  File_3_ext etc
 

<script type="text/javascript">
document.addEventListener('DataPageReady', fileInputEvent)

function fileInputEvent() {

 const fileFields = ['File_1', 'File_2'];
 

 fileFields.forEach(el=>{
   document.querySelector(`#InsertRecord${el}`).addEventListener('change', fileInputHandler);
 });

 document.removeEventListener('DataPageReady', fileInputEvent)
}

function fileInputHandler(event) {

 //Store file size

 const fileSizeInput = document.querySelector(`#${event.target.name}_size`); 
 fileSizeInput.value = event.target.files[0].size;
 
//Store file extension

const fileSizeExt = document.querySelector(`#${event.target.name}_ext`); 
 fileSizeInput.value = event.target.files[0].name.split('.').pop();
 

}

</script>

Regards,

vitalikssssss

Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...