You are viewing limited content. For full access, please sign in.

Discussion

Discussion

File Upload Name Change

posted on July 17, 2018

Trying to capture the name of the uploaded file so I can create a folder using that name. I'm trying to capture the new name in case the file changes (I've limited the upload to only one file):

As you can see, the issue I'm having is that it's not providing me with the file name but with the words "object". I've tried multiple things getting the same result, which makes me think what's highlighted above is where I'm going wrong.

Any ideas?

0 0
replied on July 18, 2018 Show version history

OK, this brings a new issue. I need to trigger a change event after I've set the Field15, otherwise, my formula in the "Subfolder" field doesn't execute. Like this post suggests:

https://answers.laserfiche.com/questions/135235/Formula-not-triggered-by-field-populated-with-javascript#135241

I tried throwing in a .change(), but it didn't work. Any ideas?

$(document).ready(function(){

//When Transmittal Upload Changes
  $('.transmittal').change(function(){

    document.getElementById('Field15').value = '';
    var attment = $('.ellipsis').attr('title');

    (document.getElementById('Field15').value = attment);

  });

})  //close document.ready

This is the formula I am currently using in the Subfolder field:

=LEFT(transCopy, SUB(LEN(transCopy), 4))

which works as long as a change is triggered from Field15.

0 0
replied on July 18, 2018

Hi, There is two ways you an do that.

First one is by using Regular Expressions. 

$('.upload').change(function(){
     
     document.getElementById('Field1').value = '';
     var attment = $('.ellipsis').attr('title');
     
        document.getElementById('Field1').value = attment;
     
     var fileName = document.getElementById('Field1').value;
     /[^.]*/.exec(fileName);
     document.getElementById('Field3').value = fileName;
  
   });
        

The second way is by using native string function

 $('.upload').change(function(){
     
     document.getElementById('Field1').value = '';
     var attment = $('.ellipsis').attr('title');
     
        document.getElementById('Field1').value = attment;
     
     var fileName = document.getElementById('Field1').value;
     fileName = fileName.substring(0, fileName.indexOf('.'));
     document.getElementById('Field3').value = fileName;
  
   });

They both do the same thing.

2 0
replied on July 18, 2018 Show version history

Using the native string function (the second one) worked (the first did not)! You are brilliant, Rendani! Thank you so much for your help!

0 0
replied on July 18, 2018

Gosh, two steps forward and one step back. I've started a new issue:

https://answers.laserfiche.com/questions/144972/Works-with-Preview-Mode-but-not-when-I-run-it

0 0
replied on July 18, 2018

Thank you, Rendani Mulaudzi! This is exactly what I was looking for!

0 0
replied on July 18, 2018 Show version history

Hi Gloria,


   $('.upload').change(function(){
     
     document.getElementById('Field1').value = '';
     var attment = $('.ellipsis').attr('title');
     
     document.getElementById('Field1').value = attment;
  
   });
       

Hope this helpful.

3 0
replied on July 18, 2018

Hi Gloria,


   $('.upload').change(function(){
     
     document.getElementById('Field1').value = '';
     var attment = $('.ellipsis').attr('title');
     
     document.getElementById('Field1').value = attment;
  
   });
       

Hope this helpful.

0 0
replied on July 17, 2018

Hi Gloria,

The following code sample worked for me. I used field IDs rather than custom CSS classes, but you can change the selectors to use classes pretty easily. q75 is ID of the file upload field, and q64 is the ID of the text field that will contain the filename.

$(document).ready(function () {
  $('#q75 input').on('change', function() {
    var filename = $('input[type=file]').val().split('\\').pop();
    $('#q64 input').val(filename);
  })
})
   

I'm not sure why you had the .change() at the end of the line you highlighted---that may have been the problem. In addition, you need to include some code to extract only the file name (rather than the full path name) from the upload field.

1 0
replied on July 17, 2018

I replaced your IDs with mine and it didn't work. I then replaced with CSS classes. That didn't work either. It didn't fill in with anything. At this point, I'd be happy with the whole path too.

I had .change() because that field is then the basis of a third field that removes the .pdf. The third field didn't execute a change without it.

0 0
replied on July 17, 2018

I just want the equivalent of {/dataset/transmittal} (CSS ".transmittal"). Works when I have a second form going to a user, but I don't want that. So then I tried the second form that's saved to Laserfiche, but that didn't work. It didn't populate like it does for a user task.

0 0
replied on October 18, 2019

Thank you Leif Hancox-Li . This worked perfectly for what I was trying to do.

0 0
You are not allowed to follow up in this post.

Sign in to reply to this post.