views:

13

answers:

1

I need to manipulate parts of a form in Drupal 6 based on the contents of a file field. For example:

  • if the form shows and there is a file, do x
  • if the form opens without a file, do y
  • if a file is uploaded, do z (as soon as the upload is finished)
  • if a file upload fails, or the uploaded file is deleted, do xyz (whether ahah is used or not)

Any ideas on how I get this done?

thanks

A: 

Found a solution of sorts. Using Drupal behaviors I am able to check whether the "upload" or "remove" buttons are in place and act according to them. Drupal behaviors also give the added value of updating when when ahah is used, as well.
For example, I needed a check-box to be disabled if no file was uploaded. I used this code:

drupal_add_js("
  Drupal.behaviors.FilefieldCheckbox = function(context) {
    if ($('#[filefield_id]-remove', context).size() > 0) {
      $('#[checkbox_id]').removeAttr('disabled');
    } else {
      $('#[checkbox_id]').attr('disabled', true);
    }
  }
  ", 'inline', 'footer');

you need to replace [filefield_id] and [checkbox_id], of course.

Omer