force an event from a button after deleting registration via modal

Asked

Viewed 34 times

0

I want to force a click on the panel after deleting a record via modal.

[![Panel description][1][1]

I need that right after deleting the file, it forces the panel button.

$('#btnDelteYes').click(function () {
    var id = $('#myModalDelete').data('id');    

    $.post('estrutura/excluirarquivo.php',{acao:'delete',id:id},function(r) { 
       var m = jQuery.parseJSON(r);        
       if (m.success) {         
        toastr["success"](m.msg);
        $('#myModalDelete').modal('hide');
        //=====>>>> aquii
       } else {
        toastr["error"](m.msg);
        $('#myModalDelete').modal('hide');

       }
          hideMessage();
    });
});
  • To do the simplest way of all put in the Success block the command $("#Idbotao"). Trigger(); You can see more about Trigger http://api.jquery.com/trigger/ and implement a custom event or just "click" $("#Idbotao"). Trigger("click");

2 answers

1


How are you using Materialize, just do it as follows:

$('#btnDelteYes').click(function () {
    var id = $('#myModalDelete').data('id');    

    $.post('estrutura/excluirarquivo.php',{acao:'delete',id:id},function(r) { 
       var m = jQuery.parseJSON(r);        
       if (m.success) {         
        toastr["success"](m.msg);
        $('#myModalDelete').modal('hide');

        /* Executa o evento de clique na "tab" */
        $("[href=\"#panel80\"]").click();


       } else {
        toastr["error"](m.msg);
        $('#myModalDelete').modal('hide');

       }
          hideMessage();
    });
});

Example:

$("#btn").click( function() {
  $("[href=\"#panel80\"]").click();
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<!-- Compiled and minified CSS -->
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/materialize/0.100.2/css/materialize.min.css">

<!-- Compiled and minified JavaScript -->
<script src="https://cdnjs.cloudflare.com/ajax/libs/materialize/0.100.2/js/materialize.min.js"></script>

<div class="row">
  <div class="col s12">
    <ul class="tabs">
      <li class="tab col s3"><a class="active" href="#test1">Test 1</a></li>
      <li class="tab col s3"><a href="#panel80">Test 2</a></li>
      <li class="tab col s3 disabled"><a href="#test3">Disabled Tab</a></li>
      <li class="tab col s3"><a href="#test4">Test 4</a></li>
    </ul>
  </div>
  <div id="test1" class="col s12">Test 1</div>
  <div id="panel80" class="col s12">Test 2</div>
  <div id="test3" class="col s12">Test 3</div>
  <div id="test4" class="col s12">Test 4</div>
</div>

<button id="btn" class="button">Acessar Tab 2</button>

If you want to refresh the page, just run: window.location.reload()

Example:

$('#btnDelteYes').click(function () {
    var id = $('#myModalDelete').data('id');    

    $.post('estrutura/excluirarquivo.php',{acao:'delete',id:id},function(r) { 
       var m = jQuery.parseJSON(r);        
       if (m.success) {         
        toastr["success"](m.msg);
        $('#myModalDelete').modal('hide');

        /* Recarrega a página */
        window.location.reload()


       } else {
        toastr["error"](m.msg);
        $('#myModalDelete').modal('hide');

       }
          hideMessage();
    });
});

0

Use the trigger passing the click as a parameter.

 $('#btnDelteYes').click(function () {
    var id = $('#myModalDelete').data('id');    

    $.post('estrutura/excluirarquivo.php',{acao:'delete',id:id},function(r) { 
       var m = jQuery.parseJSON(r);        
       if (m.success) {         
        toastr["success"](m.msg);
        $('#myModalDelete').modal('hide');
        $('#seuBotao').trigger('click'); //id do seu botão
       } else {
        toastr["error"](m.msg);
        $('#myModalDelete').modal('hide');

       }
          hideMessage();
    });
});

$('#bt2').click(function(){
    alert('botao 2 clicado');
})

$('#bt1').click(function(){
   $('#bt2').trigger('click');

})
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<button id="bt1"> bt1 </button>
<button id="bt2" disabled> bt2 </button>

  • It did not roll, the screen was stopped with the record that was deleted. <li class="Nav-item"> <a id="btnpdf" class="Nav-link Waves-light Waves-Effect Waves-light" data-toggle="tab" href="#panel80" role="tab"><i class="fa fa-file-pdf-o fa-2x" Aria-Hidden="true"></i><br> PDF FILES’S</a> </li>

  • How not? I edited the example, put another one below that uses the function trigger('click'), see her in operation.

  • Jorge, I edited exactly as you indicated, but nothing happens, the screen is with the same records, to update I need to click on F5 or click on another panel and go back to it

  • What action is this target button of trigger is performing?

  • This is the button. it already has a href identifier="#panel80" <li class="Nav-item"> <a class="Nav-link Waves-light Waves-Effect Waves-light" data-toggle="tab" href="#panel80" role="tab"><i class="fa-file-pdf-o fa-2x" Aria-Hidden="true"></i><br> PDF FILES’S</a> </li>

  • Jorge, I discovered the problem, actually it is coming in the panel, the problem and other, I need to redo the query(sql) panel, so that the deleted record is gone from the screen.

  • I expected the problem was in the função executed on that button, so mark the right answer that helped you solve your problem.

Show 2 more comments

Browser other questions tagged

You are not signed in. Login or sign up in order to post.