Skip to content

Commit

Permalink
Revisi Select Fakultas Jurusan dan Program Studi
Browse files Browse the repository at this point in the history
  • Loading branch information
BlowTorchhh committed Sep 22, 2023
1 parent 0ecd96a commit 3276ee4
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 27 deletions.
1 change: 1 addition & 0 deletions app/Models/ProgramStudi.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ class ProgramStudi extends Model
{
use HasFactory;

protected $table = 'program_studi';
protected $guarded = ['id'];

public function fakultasJurusan()
Expand Down
15 changes: 15 additions & 0 deletions public/assets/js/mahasiswa/pendaftaran.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,4 +59,19 @@ $(document).ready(function () {
$("#noFile").text(filename.replace("C:\\fakepath\\", ""));
}
});

$("#fakultas_jurusan").select2();

$("#program_studi").select2();


});
function toggleOptionVisibility() {
var selectElement = document.getElementById("fakultas_jurusan");
var optionElement = document.getElementById("option1");

if (selectElement.value != "nilai1") {
optionElement.setAttribute("hidden", "hidden");
optionElement.setAttribute("disabled", "disabled");
}
}
60 changes: 33 additions & 27 deletions resources/views/pages/mahasiswa/pendaftaran.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -364,19 +364,24 @@ class="form-control @error('tanggal_lahir') is-invalid @enderror"
<div class="row">
<div class="col-md-6">
<div class="form-group">
<label class="form-control-label" for="fakultas_jurusan">Fakultas Jurusan</label>
<label class="form-control-label" for="fakultas_jurusan">Fakultas
Jurusan</label>
<select name="fakultas_jurusan" id="fakultas_jurusan"
class="form-control @error('fakultas_jurusan') is-invalid @enderror">
<option hidden>Pilih Fakultas</option>
class="form-control @error('fakultas_jurusan') is-invalid @enderror"
style="width: 100%" onchange="toggleOptionVisibility()">
<option id="option1" >Pilih Fakultas Jurusan</option>
@foreach ($fakultasJurusan as $item)
<option @if (old('fakultas_jurusan') == $item->id) {{ 'selected' }} @endif
value="{{ $item->id }}">{{ $item->nama_fakultas_jurusan }}</option>
<option
@if (old('fakultas_jurusan') == $item->id) {{ 'selected' }} @endif
value="{{ $item->id }}">
{{ $item->nama_fakultas_jurusan }}</option>
@endforeach
</select>

@error('fakultas_jurusan')
<div class="invalid_feedback">
<span class="text-danger" style="font-size: small">{{ $message }}</span>
<span class="text-danger"
style="font-size: small">{{ $message }}</span>
</div>
@enderror
</div>
Expand All @@ -385,21 +390,23 @@ class="form-control @error('fakultas_jurusan') is-invalid @enderror">
<div class="row">
<div class="col-md-6">
<div class="form-group">
<label class="form-control-label" for="program_studi">Program Studi</label>
<label class="form-control-label" for="program_studi">Program
Studi</label>
<select name="program_studi" id="program_studi"
class="form-control @error('program_studi') is-invalid @enderror">
<option >Pilih Program Studi</option>
class="form-control @error('program_studi') is-invalid @enderror"
style="width: 100%">
<option>Pilih Program Studi</option>
</select>

@error('program_studi')
<div class="invalid_feedback">
<span class="text-danger" style="font-size: small">{{ $message }}</span>
<span class="text-danger"
style="font-size: small">{{ $message }}</span>
</div>
@enderror
</div>
</div>
</div>

</div>
<div id="step-4" class="tab-pane" role="tabpanel" aria-labelledby="step-4">
<div class="d-flex justify-content-start mt-4">
Expand All @@ -426,22 +433,21 @@ class="form-control @error('program_studi') is-invalid @enderror">
<script src="{{ asset('assets') }}/js/mahasiswa/pendaftaran.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.6.0/jquery.min.js"></script>
<script>
$(document).ready(function () {
// Saat select pertama berubah, filter data menu berdasarkan fakultas jurusan yang dipilih
$("#fakultas_jurusan").change(function () {
var fakultas_jurusan_id = $(this).val();
$("#program_studi").empty();
@foreach($programStudi as $item)
if ({{ $item->fakultas_jurusan_id }} == fakultas_jurusan_id) {
$("#program_studi").append(
$("<option></option>")
$(document).ready(function() {
// Saat select pertama berubah, filter data menu berdasarkan fakultas jurusan yang dipilih
$("#fakultas_jurusan").change(function() {
var fakultas_jurusan_id = $(this).val();
$("#program_studi").empty();
@foreach ($programStudi as $item)
if ({{ $item->fakultas_jurusan_id }} == fakultas_jurusan_id) {
$("#program_studi").append(
$("<option></option>")
.attr("value", "{{ $item->id }}")
.text("{{ $item->nama_program_studi }}")
);
}
@endforeach
);
}
@endforeach
});
});
});
</script>
@endsection

0 comments on commit 3276ee4

Please sign in to comment.