Hi,

I would like to chande the behaviour of the "Upload" and the "Remove" buttons. I would like them to listen to the mouseup-event instead of the mousedown-event. The best solution would be if I could acomplish this through my own module.

I got it working through a patch of the fielefield_widget.inc. Than I tried to make the changes inside a pre_render function but this has no effects.

How I tried it (and it does not work):

function module_name_form_alter(&$form, $form_state, $form_id) {
  .
  .
  .
  $form['field_name']['#pre_render'][] = 'module_name_alter_ahah';
  .
  .
  .
}

function module_name_alter_ahah($elements){
  $elements[0]['filefield_upload']['#ahah']['event'] = 'mouseup';
  return $elements;
}

Any ideas how to accomplish this?

Thanks,
dendie

Comments

braindrift’s picture

Category: feature » support
quicksketch’s picture

I don't think this is possible. There was a long thread about how "click" events don't work properly for buttons as a #ahah property, otherwise that would be used instead of "mousedown". "mouseup" won't work at all because the form has already been submitted during the "click" event and "mouseup" is fired afterwards, meaning that the form would already be submitted normally without JavaScript by the time "mouseup" fires.

braindrift’s picture

but it works fine when I add an 'event' => 'mouseup' in filefield_widget_process function

quicksketch’s picture

Hm, well if you want to give it a shot you can implement hook_elements() and add your own #process function to FileField elements. This allows you to add your own processing (and change the #ahah property) after filefield_widget_process() has already run.

braindrift’s picture

Thanks for the hint. That works!!!

braindrift’s picture

Status: Active » Closed (fixed)
braindrift’s picture

@quicksketch: Just to ensure, is that the right way, or would you suggest an other one?

function my_module_elements() {
  $elements = array();
  $elements['filefield_widget']['#process'] = array('my_module_filefield_widget_process'); 
  $elements['imagefield_widget']['#process'] = array('my_module_imagefield_widget_process'); 
  return $elements;
}

function my_module_filefield_widget_process($element, $edit, &$form_state, $form){
  $element = filefield_widget_process($element, $edit, &$form_state, $form);
  $element['filefield_upload']['#ahah']['event'] = 'mouseup';
  $element['filefield_remove']['#ahah']['event'] = 'mouseup';
  return $element;
}

function my_module_imagefield_widget_process($element, $edit, &$form_state, $form){
  $element = imagefield_widget_process($element, $edit, &$form_state, $form);
  $element['filefield_upload']['#ahah']['event'] = 'mouseup';
  $element['filefield_remove']['#ahah']['event'] = 'mouseup';
  return $element;
}
braindrift’s picture

Status: Closed (fixed) » Fixed
quicksketch’s picture

You actually shouldn't need to call the normal *_widget_process() functions at all. Make sure your module has a "weight" value greater than imagefield and filefield in the "system" database table, then you should just be able to do this:

function my_module_elements() {
  $elements = array();
  $elements['filefield_widget']['#process'] = array('my_module_filefield_widget_process');
  $elements['imagefield_widget']['#process'] = array('my_module_filefield_widget_process');
  return $elements;
}

function my_module_filefield_widget_process($element, $edit, &$form_state, $form){
  $element['filefield_upload']['#ahah']['event'] = 'mouseup';
  $element['filefield_remove']['#ahah']['event'] = 'mouseup';
  return $element;
}

The #process callbacks are merged recursively from hook_elements(), you just have to make sure that yours comes after filefield/imagefield.

braindrift’s picture

Thanks!

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.