DoubleUp's avatar

Laravel On click Event Button [Enable button after condition met]

Hello guys, I have a table which contain two buttons, one is for uploading a file and the other one is for giving score. What I want to do is to give a condition for the second button which is the scoring button, whereby it can't be clicked (disabled) if there is no file uploaded. my upload button loaded a different page. The 'penilaian' (Scoring) button will check on the if there is a file uploaded, if there is a file, it will be enable to the user to click the scoring button/ How can I achieve this?

Here is what my table looks like:

enter image description here

And here is my AdminController for the table

public function showpekerjaanppk(){
        if(Auth::user()->status=='super'){
            $pekerjaan = Pekerjaan::with('penyedia','user')->paginate();
            return view('admin.showpekerjaan', compact('pekerjaan'));
        }else{
            $pekerjaan = Auth::user()->pekerjaans;
            return view('admin.showpekerjaan', compact('pekerjaan'));
        }
        //return view('admin.showpekerjaan', compact('penyedia','pekerjaan','totalAvg'));
    }

And here is my blade file for the table

<section class="content">
    <div class="container-fluid">
        <div class="row">
            <div class="col-12">
              <div class="card">
                <div class="card-header">
                  @if (Auth::user()->status=='super')
                  <h3 class="card-title"><b>{{$penyedia->nama}}</b></h3> <br>
               
                  <h3 class="card-title">Nilai Total: <b>{{$totalAvg}}</b></h3> 
                  @else
                  <h3 class="card-title"><b></b></h3> <br>
               
                    <h3 class="card-title"></b></h3>
                  @endif
                <!-- /.card-header -->
                <div class="card-body table-responsive">
                  <table id="tabelpekerjaan" class="table table-bordered">
                    <thead>
                      <tr>
                        <th style="width: 10px" rowspan="2">No.</th>
                        <th rowspan="2">Tanggal</th>
                        <th rowspan="2">Paket Pekerjaan</th>
                        <th rowspan="2">Nama Perusahaan</th>
                        <th rowspan="2">Lokasi Pekerjaan</th>
                        <th rowspan="2">PPK</th>
                        <th rowspan="2">Nilai Kontrak</th>
                        <th rowspan="2">Nilai</th>
                        <th rowspan="2">BAHP</th>
                        <th colspan="2">Aksi</th>
                      </tr>

                      <tr>
                        <td>BAHP</td>
                        <td>Nilai</td>
                      </tr>
                    </thead>
                    <tbody>
                      @php $no = 1; /*$totalNilai = 0.0;*/ @endphp
                      @foreach ($pekerjaan as $pekerjaans)
                      <tr>
                        <td>{{$no++}}</td>
                        <td>{{$pekerjaans->tanggal}}</td>
                        <td>{{$pekerjaans->pekerjaan}}</td>
                        <td>{{$pekerjaans->penyedia->nama}}</td>
                        <td>{{$pekerjaans->lokasi}}</td>
                        <td>{{$pekerjaans->user->name}}</td>
                        <td>Rp. {{number_format($pekerjaans->nilai_kontrak,0,',',',')}}</td>
                        @php
                        $pekerjaans->nilai_total = $pekerjaans->nilai_1 + $pekerjaans->nilai_2 + $pekerjaans->nilai_3 + $pekerjaans->nilai_4;
                        @endphp
                        <td>{{$pekerjaans->nilai_total}}</td>
                        <td>{{$pekerjaans->bahp}}</td>
                        <td>
                          <a href="/bahp/{{$pekerjaans->id}}" type="button" class="btn btn-outline-primary">Upload</a>
                        </td>
                        <td>
                            <a href="/nilai/{{$pekerjaans->id}}" type="button" class="btn btn-outline-primary">Penilaian</a> //disabled untill file uploaded
                        </td>
                      </tr>
                      @endforeach
                    </tbody>
                  </table>
                </div>
                <!-- /.card-body -->
              </div>
              <!-- /.card -->
              @if (Auth::user()->status=='super')
              <div class="card-footer">
                
                <a href="/datanilai_penyedia" type="button" class="btn btn-outline-secondary">Kembali</a>
                
              </div>
              @endif
            
    </div>
</section>

Thank you in advance.

0 likes
5 replies
Snapey's avatar

Assuming your page is reloaded after the file upload then you just need a way to determine the state of the upload.

If you are uploading without reloading the page then you better say what you use.

As far as I can see, the upload button just loads a different page?

DoubleUp's avatar

@Snapey Yes, my upload button loaded a different page. The 'penilaian' (Scoring) button will check on the if there is a file uploaded, if there is a file, it will be enable to the user to click the scoring button

Snapey's avatar

then you just need a way to determine the state of the upload.

1 like
DoubleUp's avatar

@Snapey Thanks, I already did it by using this:

@if (is_null($pekerjaans->bahp))
                            <a href="/nilai/{{$pekerjaans->id}}" type="button" class="btn btn-outline-secondary disabled">Penilaian</a>
                            @else
                            <a href="/nilai/{{$pekerjaans->id}}" type="button" class="btn btn-outline-primary">Penilaian</a>
                            @endif

The problem is someone can just edit out the disabled in devtools (f12), and just click the button to access the page....

Snapey's avatar

@DoubleUp You don't have to accept the request. You should check that they are allowed to see the data

They would not need to alter the html, they could just put /nilai/1234 in the browser address bar

1 like

Please or to participate in this conversation.