Hi there,

Wondering if it'd be feasible to extend a conditional trigger to the file upload component. Currently you can't trigger things based on the value of an upload field, but you can for most other component types (file components are not available in the 'if' drop down).

My use case is that if a user does not select a file, they don't get to answer additional text-based questions.

I realize file inputs are bit tricky compared to testing other types of input components, but I think it would be nice to complete the conditionals with access to this logic.

I've come up with my own Javascript for testing this to change the way the upload widget looks (classes and CSS), but I think someone could extend it to work for Webform Conditional checks:

var f = $('.file-upload-wrapper');
var l = $('.file-upload-wrapper label');
var t = l.text(); // Original label text

if (f.find('.form-item input.form-file').val() !== '') {
    f.addClass('loaded removable');
  }
  
  f.on("change", ".form-item input.form-file", function(){
    if (jQuery(this).val() !== '') {
      f.addClass('loaded');
      l.text('File Ready!');
    }
    else {
      f.removeClass('loaded');
      l.text(t);
    }
  });

Comments

amaisano created an issue. See original summary.

amaisano’s picture

Issue summary: View changes
DanChadwick’s picture

Status: Active » Closed (won't fix)

It would be feasible, but I don't plan to do it. If someone were to post a patch, and if the community tested it well, I would be amenable to committing it. Anyone can feel free to reopen with a patch, now or in the future.

Uploading files is sort of broken now in Drupal 7 core. Actually clicking the "upload" button generates a new form build id due to the way the ajax file upload request is handled. In some cases, this causes problems for modules, webform included. Our suggested solution has been to hide the upload button, which isn't needed because the file will upload upon form submission without it.

My suggestion for you would be to set a hidden field with javascript and use conditionals based on that hidden field. No that the field can't be configured as "secure" as these values aren't sent to the browser (or they wouldn't be secure).