Home » Jquery » javascript – How to change checkbox by icon validate in datatable using jQuery and laravel?

javascript – How to change checkbox by icon validate in datatable using jQuery and laravel?

Posted by: admin February 22, 2020 Leave a comment

Questions:

I have two forms, the form1 contains the date and a show button that hides the form1 and displays the form2 which also contains a table salaries and checkboxes and a validation button, I want when I click on the button display it is necessary to check if there is already in the table pointages the chosen dateS and the matriculeS if yes I wish that the checkbox changes with a valid icon otherwise the checkbox remains unchanged.

summarize: table pointage (id, datep, personnel numberP). If there are in the pointages table datep=dateS and matriculeP=matriculeS checkbox change by icon validate.

valider.blade.php

<div id="form1">
  <div class=" col-md-10 col-md-offset-1">
   <div class="form-group col-md-3">
    <label for="titre">date</label>
   </div>
   <div class="form-group col-md-5">
     <input type="date" name="dateS" id="dateS" class="form-control">
   </div>
  </div>
  <div class="col-md-6 col-md-offset-3">
    <div class="form-group col-md-2">
     <button class="btn btn-primary" id="hide" data-url="">show</button>
    </div>
  </div>
</div>
<div id="form2">
   <div class="col-md-10 col-md-offset-1">
            <h4>dateS : <span id="da"></span></h4>
        </div>
            <table id="example" class="table table-striped table-bordered" style="width:100%">
                 <thead>
                  <tr>
                    <th><input type="checkbox" id="check_all"></th>
                    <th>matriculeS</th>
                    <th>name</th>
                  </tr>
                 </thead>
                <tbody>
                  @foreach($salaries as $salarie)
                  <tr id="{{$salarie->id}}">
                    <td><input type="checkbox" class="checkbox" name="customer_id[]" value="{{$salarie->id}}" /></td>
                    <td>{{ $salarie->id }}</td>
                    <td>{{ $salarie->prenom }}</td>
                  </tr>
                  @endforeach
                </tbody>
            </table>
          <div class="col-md-6 col-md-offset-3">
          <div class="form-group col-md-2">
           <button class="btn btn-primary" id="valider" data-url="">Validate</button>
          </div>
        </div>

</div>

jQuery

 <script type="text/javascript">
  $(document).ready(function () {
    $("#form2").hide();
    let dateS = $("#dateS").val();
    $("tr").each(function(i, r) {

      let matriculeS = r.cells[5].innerText;
      if (dateS=dateP && matriculeS=matriculep) {
        $(r).find("input").first().replaceWith('<span style="color: green;font-weight: bolder;">✔</span>');//✓ - 
      }
    });

    $("#hide").click(function(){

      $("#form1").hide();
      $("#form2").show();
      let dat = $("#dateS").val();
      $("#da").text(dat);
    });

    $("#valider").click(function() {

    $("tr").each(function(i, r) {
      if (i > 0 && $(r).find("input").first().prop("checked")) {
        $(r).find("input").first().replaceWith('<span style="color: green;font-weight: bolder;">✔</span>');//✓ - 

      }
    });
  });


    });
  </script>

SalarieController.php

public function valider(){
      $salaries = Salarie::get();
      $pointages = Pointage::get();
      return view('salarie.valider',compact('salaries','pointages'));
    } 

web.php

Route::get('valider', '[email protected]');
How to&Answer: