Untitled

mail@pastecode.io avatar
unknown
plain_text
10 days ago
5.0 kB
0
Indexable
Never
modal soft

<meta name="csrf-token" content="{{ csrf_token() }}">
<div class="modal fade" id="modal-kompsoft" aria-labelledby="modalKompSoftLabel" aria-hidden="true" 
data-route="{{ route('edit-jobprofileeditkomhardsoft') }}" 
data-route2="{{ route('jobprofile-fetch-softkompetensi') }}" 
data-route3="{{ route('jobprofile-fetch-soft') }}" 
data-route4="{{ route('jobprofile-hapus-hardsoft') }}" 
data-route5="{{ route('jobprofile-fetch-rumpun') }}">
  <div class="modal-dialog modal-xl modal-dialog-centered modal-dialog-scrollable">
    <div class="modal-content">
      <div class="modal-header">
        <h1 class="modal-title fs-5" id="staticBackdropLabel">Edit Kompetensi Technical: Soft Skills</h1>
        <button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
      </div>
      
      <div class="modal-body">
        <form id="form-kompsoft" method="POST">
          @csrf

          <div class="row">
            <div class="col-sm-6">
              <ul id="listContainersoft" class="list-group"></ul>

              <div style="margin-bottom: 16px;">
                <div class="row">
                  <div class="col-md-9">
                    <p class="body-title">Pilih Kompetensi</p>
                    <select id="kompetensisoft" class="form-select select2" style="width: 100%;" data-placeholder="Kompetensi">
                      <option value="" selected>Silahkan dipilih</option>
                    </select>
                  </div>
                </div>
              </div>

              <div id="selectedKompetensiSoft">
                 <!-- Selected kompetensi will be appended here -->
              </div>

              <span class="divider"></span>
            </div>

            <div class="col-sm-6">
              <p class="body-title" style="text-align:center">Kamus Kompetensi</p>
              <hr>
              <div class="nama-kompetensi">
                <p style="font-weight: 600; text-align:left">Nama Kompetensi:</p>
                <p style="text-align:left" id="namakompetensisoft"></p>
              </div>
              <div class="desc-kompetensi">
                <p style="font-weight: 600; text-align:left">Definisi:</p>
                <p style="text-align:left" id="desckompetensisoft"></p>
              </div>
            </div>
          </div>
        </form>
      </div>
      
      <div class="modal-footer justify-content-between">
        <div>
          <button type="button" class="btn btn-batal" data-bs-dismiss="modal">Batal</button>
        </div>
        <div>
          <button type="submit" class="btn btn-primary">Simpan</button>
        </div>
      </div>
    </div>
  </div>
</div>

js

<script>
$(document).ready(function () {
    $('#modal-kompsoft').on('shown.bs.modal', function () {
        // Reset select element and clear descriptions when the modal opens
        $('#kompetensisoft').val(null).trigger('change');
        $('#desckompetensisoft').text('');
        $('#namakompetensisoft').text('');

        // Event listener for changes on the select element
        $('#kompetensisoft').on('change', function () {
            var selectedId = $(this).val();
            var selectedText = $(this).find('option:selected').text();

            if (selectedId) {
                updateDescriptionSoft(selectedId, selectedText);
            }
        });
    });
});

function updateDescriptionSoft(selectedValue, selectedText) {
    var idIdentitas = $('input[name="ididentitasjbtn"]').val();
    var data = {
        ididentitasjbtn: idIdentitas,
        id: selectedValue,
        koderumpun: 0, // Set koderumpun to 0
        kodejeniskomp: 2 // Set kodejeniskomp to 2
    };
    var fetchUrl = $('#modal-kompsoft').data('route5');

    $.ajax({
        url: fetchUrl,
        type: "GET",
        data: data,
        beforeSend: function() {
            // Show loading indicator
            $('#desckompetensisoft').text('Loading...');
        },
        success: function (response) {
            console.log('AJAX Response:', response); // Log the response
            
            var nameElement = $('#namakompetensisoft');
            var descriptionElement = $('#desckompetensisoft');

            if (response.result) {
                nameElement.text(selectedText || '');
                let dataFetch = response.result.result.find((data) => {
                	return data.namakomphardsoft == selectedText;
                });
                descriptionElement.text(dataFetch.desckomphardsoft || '');
            } else {
                console.error("No matching item found for id:", selectedValue);
                descriptionElement.text('No matching description found.');
            }
        },
        error: function (xhr, status, error) {
            console.error('Error fetching description:', error);
            $('#desckompetensisoft').text('Error fetching description.');
        }
    });
}
</script>
Leave a Comment