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

Question

Question

Forms - Javascript selector for file upload field

asked on September 24, 2014

If the selector for a text field is 'input' what is it for a file upload field?

0 0

Answer

SELECTED ANSWER
replied on September 26, 2014

Try this:

$(document).ready(function() {
  $(document).on('click','.req .fileuploader',function() {
    alert('hi');
  });
});

Replace the alert with the desired code.

0 0

Replies

replied on September 25, 2014

You can use .fileuploader to target the Choose Files button. The list of uploaded files is in a table, like so: $('.files tbody tr')

0 0
replied on September 26, 2014

I tried the following and it does not appear to be working. I am trying to change the file up loader to a required field.

 

  $('.toggleField').change(toggleRequiredFields);
  
  function toggleRequiredFields() {
    $('.req fileuploader').each(function() {
      if ($(this).is(':hidden')) {
        $(this).removeAttr('required');
      } else {
        $(this).attr('required',true);
      }
    });
  }


OR

    $('.toggleField').change(toggleRequiredFields);
  
  function toggleRequiredFields() {
    $('.req tbody tr').each(function() {
      if ($(this).is(':hidden')) {
        $(this).removeAttr('required');
      } else {
        $(this).attr('required',true);
      }
    });
  }

 

 

0 0
replied on September 26, 2014 Show version history

fileuploader is a CSS class, so you need to put a period before it in line 4.

$('.req .fileuploader')

0 0
replied on September 26, 2014

Oh, I have the CSS class set as req, I was just trying to find the replacement for input. Previously it was $( '.req input' )

0 0
SELECTED ANSWER
replied on September 26, 2014

Try this:

$(document).ready(function() {
  $(document).on('click','.req .fileuploader',function() {
    alert('hi');
  });
});

Replace the alert with the desired code.

0 0
replied on September 29, 2014 Show version history

I ended up finding out we no longer need to use Javascript to set hidden fields as required. I guess this was only in the older versions and I was under the impression that it was still needed. Thanks though!

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

Sign in to reply to this post.