If the selector for a text field is 'input' what is it for a file upload field?
Question
Question
Answer
Try this:
$(document).ready(function() { $(document).on('click','.req .fileuploader',function() { alert('hi'); }); });
Replace the alert with the desired code.
Replies
You can use .fileuploader to target the Choose Files button. The list of uploaded files is in a table, like so: $('.files tbody tr')
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); } }); }
fileuploader is a CSS class, so you need to put a period before it in line 4.
$(
'.req .fileuploader'
)
Oh, I have the CSS class set as req, I was just trying to find the replacement for input. Previously it was $( '.req input' )
Try this:
$(document).ready(function() { $(document).on('click','.req .fileuploader',function() { alert('hi'); }); });
Replace the alert with the desired code.
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!