Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

All Delete button not work with laravel 4 #178

Open
hanyelbana opened this issue Aug 1, 2013 · 10 comments
Open

All Delete button not work with laravel 4 #178

hanyelbana opened this issue Aug 1, 2013 · 10 comments
Labels

Comments

@hanyelbana
Copy link

All delete button open the modal but with confirmation it returned to list page with no delete from the list and no delete from database.

public function postDelete($comment)
{
    // Declare the rules for the form validation
    $rules = array(
        'id' => 'required|integer'
    );

    // Validate the inputs
    $validator = Validator::make(Input::all(), $rules);

    // Check if the form validates with success
    if ($validator->passes())
    {
        $id = $comment->id;
        $comment->delete();

        // Was the comment post deleted?
        $comment = Comment::find($id);
        if(empty($comment))
        {
            // Redirect to the comment posts management page
            return Redirect::to('admin/comments')->with('success', Lang::get('admin/comments/messages.delete.success'));
        }
    }
    // There was a problem deleting the comment post
    return Redirect::to('admin/comments')->with('error', Lang::get('admin/comments/messages.delete.error'));
}
@dgafitescu
Copy link

I notice that as well , if you remove the class close_popup from the

 <button type="submit" class="btn btn-danger close_popup">Delete</button>

in https://github.com/andrew13/Laravel-4-Bootstrap-Starter-Site/blob/master/app/views/admin/comments/delete.blade.php
the delete would work but the popup will stay up

@andrew13
Copy link
Collaborator

andrew13 commented Aug 2, 2013

I'll confirm this later. Likely is fixed in develop branch.

@florinvirdol
Copy link

I encountered the same issue, delete buttons not working, or happens as @dgafitescu noticed.

@andrew13 , do you have any news on this one? Thanks!

@gplv2
Copy link

gplv2 commented Aug 15, 2013

I see the same issue, i've been debugging it in depth and came to the same conclusion, by removing close_popup the postDelete action is performed and the server sees the incoming POST call. With that class enabled, on the server end it doesn't even receive a POST action from that delete popup page. I've tested it with Advanced REST client (chrome app) and when using the _token from the GET call + the id the delete does work when manually performed.

@thuansb
Copy link

thuansb commented Sep 1, 2013

I already resolved it as following:

#Issue 1: when click outsite the colorbox, the colorbox is close but the parrent table is not updated.

Edit the file: views\admin\blogs\index.blade.php

Add script to $(".iframe").colorbox function

    onClosed: function(){
                        oTable.fnReloadAjax();
                    }

to reload the table everytime we close the colorbox

#Issue 2: (this issue)
Edit the file: views\admin\layouts\modal.blade.php

I use jquery to submit the form instead of manual submit the form. Add following code to $(document).ready() function

$(function() {
              $('form').submit(function(event) {
                var form = $(this);
                $.ajax({
                  type: form.attr('method'),
                  url: form.attr('action'),
                  data: form.serialize()
                }).done(function() {
                  // Optionally alert the user of success here...
                  parent.$.colorbox.close();                  
                }).fail(function() {
                  // Optionally alert the user of an error here...
                });
                event.preventDefault(); // Prevent the form from submitting via the browser.
              });
            });

@thuansb
Copy link

thuansb commented Sep 1, 2013

Note: if you use $('form').submit() it will submit and close all forms. That mean, when you submit edit/create form, it will close after submit too. So you should use id selector instead of, may be '#deleteForm'.

@christoferd
Copy link

@andrew13 , do you have any news on this one? Thanks : )
Update us if it's resolved in Dev Branch please.

@ghost
Copy link

ghost commented Oct 18, 2013

What I have done to make it work...

modal.blade.php
  $(document).ready(function(){
    $('.close_popup').click(function(){
      parent.oTable.fnReloadAjax();
      parent.jQuery.fn.colorbox.close();
      return false;
    });
    $(function() {
      $('#deleteForm').submit(function(event) {
        var form = $(this);
        $.ajax({
          type: form.attr('method'),
          url: form.attr('action'),
          data: form.serialize()
        }).done(function() {
          parent.jQuery.colorbox.close();
          parent.oTable.fnReloadAjax();
        }).fail(function() {
        });
        event.preventDefault();
      });
    });
  });
  $('.wysihtml5').wysihtml5();
  $(prettyPrint);

@asivaneswaran
Copy link

@MartinOlsansky

It doesn't work for me. I added an id to my form with deleteForm.
but it doesn't work...

The popup doesnt close after it's finished....

Thanks,
Ara

@pascal08 pascal08 mentioned this issue Nov 19, 2013
@khaertel
Copy link

@asivaneswaran you still need to remove close_popup in

Delete

as suggested by @dgafitescu above. This works for me fine.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

10 participants