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.
change
method. Perhaps you meant to put that asevent
? 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.hook_field_widget_form_alter
to do the above (comment) instead of plain hook_form_alter