Jump to content

Is there a callback when an add had been cancelled?


  • Please log in to reply
2 replies to this topic

#1 Katherine



  • Members
  • Pip
  • 6 posts

Posted 10 August 2013 - 02:03 PM

I mixed grocery crud and image crud. In my grocery crud add form, theres an iframe pointing to the image crud.


In image crud everytime I upload, it automatically inserts to database with a temporary value in the foreign key column. Once submitted, this field will be updated base on the primary key id of the newly inserted data.


There will be an instance when the user will not submit the grocery crud form so the image that had been uploaded will be left in the database without being used.


So I plan to put a callback when the cancel button had been clicked and this will delete those inserted photos in the database.


Is it possible?

#2 davidoster


    Grocery CRUD Ninja

  • Advanced Member
  • PipPipPip
  • 1,068 posts
  • LocationAthens, Greece

Posted 11 August 2013 - 05:24 AM

There isn't a callback for the cancel button.

You need to do this via js/jQuery and an ajax call to a controller function.



rtfm_small.jpg---!!!Please read these guidelines before asking to the forums!!!---



David Oster aka George Pasparakis,

#3 Amit Shah

Amit Shah

    grocery CRUD Master

  • Advanced Member
  • PipPipPip
  • 1,192 posts
  • LocationMumbai, India

Posted 27 March 2014 - 02:53 PM

Well i was facing the same trouble and i thought over the same and came to this conclusion....

we can achieve the same functionality by over riding its base functionality ... or altering the themes js itslef.. whichever works the best for you. Here is the script that works out for me... can do the same for you

$(document).ready(function() {
     //Now this is very important here - to give time out in case you are overriding it using yr seperate script
     //Why? if not done, the second function will bind in later to this one ending up with double function call...
        function() {
            //console.log("Unbinding the event");
            $('#cancel-button').unbind("click");    ////----This is again important to unbind the GC's default functionality
            //console.log("Binding it to the new event");
            //Now we bind our own new functionality.
            $('#cancel-button').click(function(event) {
                if (confirm(message_alert_add_form)) {
                    if ($(".delete-anchor").is(":visible")) {
                        //console.log('triggering the delete click');

                        delId = $(".delete-anchor").attr('id');
                        //console.log("Got the ID - " + delId);
                        contents = delId.split("_");
                        unique_id = contents[1];
                        //console.log("Got the Unique ID - " + unique_id);
                        var file_name = $('#delete_url_' + unique_id).attr('rel');
                        //console.log("Got the File Name 2 be deleted - " + file_name);
                        var delete_url = $('#delete_url_' + unique_id).attr('href');
                        //console.log("Delete url found - " + delete_url);
                            url: delete_url + "/" + file_name,
                            cache: false,
                            success: function() {
                                //show_upload_button(unique_id, uploader_element);
                                console.log("the file was deleted")
                            beforeSend: function() {
                                //$('#upload-state-message-' + unique_id).html(string_delete_file);
                                $('#success_' + unique_id).hide();
                                $("#loading-" + unique_id).show();
                                $("#upload-button-" + unique_id).slideUp("fast");
                    } else {
                        //console.log("Nothing to delete");
                    window.location = list_url;
        }, 2000);

Do it the way you like it... i didnt want to overwrite the functionality and henceforth i wrote it out as a seperate script. But technically speaking it should be the other way around - to update the script with the above functionality.


How it works - it dose the same stuff - confirms you first for your exit. If you selects yes - it will check if the delete button is visible or not. If so, it will trigger the delete call as it dose it on the delete link click after uploading the photo. Once done, it will take you to the list url of the app / method

MIND IT / WARNING do not try and use it for edit, use it only in case of add state .. else it will delete your image file while editing also.


Hope this helps you achieve your target...


Happy GCing :)

Also tagged with one or more of these keywords: callback

0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users