Laravel-4-Bootstrap-Starter-Site icon indicating copy to clipboard operation
Laravel-4-Bootstrap-Starter-Site copied to clipboard

All Delete button not work with laravel 4

Open hanyelbana opened this issue 12 years ago • 10 comments

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'));
}

hanyelbana avatar Aug 01 '13 08:08 hanyelbana

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

dgafitescu avatar Aug 01 '13 09:08 dgafitescu

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

andrew13 avatar Aug 02 '13 17:08 andrew13

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

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

florinvirdol avatar Aug 08 '13 07:08 florinvirdol

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.

gplv2 avatar Aug 15 '13 12:08 gplv2

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 avatar Sep 01 '13 10:09 thuansb

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'.

thuansb avatar Sep 01 '13 11:09 thuansb

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

christoferd avatar Sep 01 '13 23:09 christoferd

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);

ghost avatar Oct 18 '13 09:10 ghost

@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

asivaneswaran avatar Nov 19 '13 16:11 asivaneswaran

@asivaneswaran you still need to remove close_popup in

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

khaertel avatar Jan 15 '14 19:01 khaertel