By Anonymous (not verified) on
Hi,
I'd like to call javascript functions when a managed_file field has been submitted or the image deleted. I found no solution on the web for now, does anyone have an idea ?
Hi,
I'd like to call javascript functions when a managed_file field has been submitted or the image deleted. I found no solution on the web for now, does anyone have an idea ?
Comments
can u elaborate your issue
can u elaborate your issue
Need Drupal help?
Reach me
Backend Frontend and DevOps.
Of course. I am using
Of course.
I am using managed_file in a module to upload an image without reloading the page. A managed_file field is very helpful in the upload part, however I still need to send the form to process the image by my module.
What I would like to do is to create a sort of event listener that would call a javascript function of my own when an image has been uploaded or removed of the managed_file field.
if u want to invoke a
if u want to invoke a javascript on the click event of the manage_file button "upload and delete" you can write a jquery to do that
refer http://api.jquery.com/click/
or probably you can override the manage_file element and add onclick event to that element.
refer http://api.drupal.org/api/drupal/modules!file!file.module/function/theme...
you can override the manage_file element by writing a function in your template.php suppose you theme name is active you can override by
Hope this will help u
Need Drupal help?
Reach me
Backend Frontend and DevOps.
Those two solutions won't
Those two solutions won't work and that for the same reason : I need the file to be uploaded before to call my javascript function. So I need drupal to upload the file (which it does just fine) and then call my function.
I tried to add an event listener to a hidden input that contains the image's fid but all the container is rebuilt after uploading a file therefore the event listener cannot work.
There is a secret callback
Add a callback (or several of them) to the
#file_value_callbacksfield of the managed_file. I couldn't find it documented properly but it is commented in core'sfile.modulefile.Nobody ?
Nobody ?
I Second this question
I've been trying to get the same thing working.
Google 'drupal managed_file events' and this is result #4. If anyone's come up with a way to do this, please share!
Basically, after a file is uploaded (in my case, an mp3 file), I have a separate library that is reading the ID3 tags into other fields on a custom attribute. Basically, after an upload, I'm trying to get the following to happen:
1) Show the rest of the fields (in my case, stuff like Artist, Album, Track, etc).
2) Have them prepopulated.
There has to be some kind of event (or some way to hook an event on upload_complete or something of that nature), that will fire upon a successful upload; client or server-side.
Thanks guys.
I have the same
I have the same problem...
Once the input submit #edit-ajax3-upload-button is clicked all the divs including it parent from #edit-ajax3-ajax-wrapper are rebuild...There is nothing on the API allowing a custom javascript function to act as callback.. very anoying situation.
Please if someone has a solution to this tell us !
What I finally did is to
What I finally did is to check whether the ajax process is done or not every second for fifteen seconds. It is a simple timeout loop, not perfect but it worked so far.
I wrote a tutorial on how to
I wrote a tutorial on how to call a function after an AJAX event:
http://www.jaypan.com/tutorial/calling-function-after-ahah-event-drupal-...
Contact me to contract me for D7 -> D10/11 migrations.
another way to add JS functions on remove/add managed_file event
Form API:
Helper functions:
any JS code / JS function triggers may be added in these 2 functions
using #upload_validators
I couldn't get #file_value_callbacks to work for me (the way I needed it).
#file_value_callbacks does not seem to include the file object. In my user case, I needed to parse data from a csv file as soon as it is uploaded.
I found using #upload_validators as a callback to be much better, as it includes the file object as well as you can pass your own arguments:
Quentin Campbell
I have multiple field
I want to call confirm message before remove the file .
in my custom module i have used managed_file and in my module i want to add confirm message on remove button id we click on remove button there should be one popup with confirmation. if user click on ok then and then file should be deleted if they select cancel file should not be deleted...
i have search in web but dent get any solutions,