Why does toggle inside modal won’t work in laravel?

  Uncategorised

Hi I’m currently working on a toggle(active – inactive) inside a modal.
I was able to make it work, changing active to inactive. However, turning it back to active won’t work and status stays inactive.

How can I make this work? What’s missing here?

Thanks in advance

images html
toggle button

datatable

Here’s my JS

$("#updatetaxform").on('submit', function (e) {
e.preventDefault() 
const pid = $("#updatetaxform [name=pid]").val();
const IsActive = $("#updatetaxform").prop('checked') == true ? 1 : 0;
$.ajax({
    data: {
        pid,
        IsActive
    },
    url: "/edit-tax",
    type: "POST",
    success: function (data) {
        console.log(data.success) 
        var oTable = $('#tax-info-table').dataTable()
        oTable.fnDraw(false)
        Swal({
            type: 'success',
            title: 'Success!',
            text: "Successfully updated!",
            showConfirmButton: false,
            timer: 3000
        }).then(function () {
            location.reload()
        })
       
    },
    error: function (data) {
        console.log('Error:', data.responseJSON.message);
        Swal({
            type: 'error',
            title: 'Tax Information Error',
            text: data.responseJSON.message
        })
    }
}) })

Here’s my input html

<div class="form-group">
        <label for="">Active Status</label>
        <input type="checkbox" data-toggle="toggle" data-onstyle="success" data-offstyle="danger" data-style="ios slow" data-width="100" data-height="20" name="IsActive" {{ $taxstatus->IsActive ? 'checked' : ''}}>
      </div>

Here’s my controller

public function editTax(Request $request)
{
$tax = TaxDetails::where('id', $request->id)->update(
            ['pid' => $request->pid, 'IsActive' => $request->IsActive ]
            );}

public function index()
{
  $tax1 = TaxDetails::where('pid', Session::get('pid'))->first();
  return view('pages.tax-information', [
        'taxstatus' => $tax1
        
    ]);
}

Source: Laravel 5 Questions

Leave a Reply