1

I have a content type with a file field: field_file_field . I want to attach a custom #ajax callback to the widget which will execute after file upload.

I have tried with:

$ajax_settings = array(
      'callback' => 'some_ajax_callback',
      'wrapper' => "default-wrapper",
      'method' => 'change',
      'effect' => 'fade',
    );

// All of those 3 I have tried.
$form['field_file_field']['#ajax'] = $ajax_settings;
$form['field_file_field'][LANGUAGE_NONE]['#ajax'] = $ajax_settings;
$form['field_file_field'][LANGUAGE_NONE][0]['#ajax'] = $ajax_settings;

Without success. Any idea ? I want to change another file in the edit form when upload file.

3
  • there's no change method. Perhaps you meant to put that as event? Also, as to your main question, take a look at the core file module (file.field.inc specifically). There's a #process function that gets added on the file widget, which changes the #ajax array's values, effectively after everytime you upload an image. So you may need to add your own #process function into that array, and add your #ajax there. I've never done this before though. Hence just commenting.
    – Beebee
    Commented Nov 14, 2016 at 16:51
  • Oh and you should probably use hook_field_widget_form_alter to do the above (comment) instead of plain hook_form_alter
    – Beebee
    Commented Nov 14, 2016 at 16:58
  • 1
    Can I add additional submit handler for Submit file button and somehow to update another field with javascript ? Commented Nov 14, 2016 at 20:33

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.