89 lines
3.7 KiB
PHP
89 lines
3.7 KiB
PHP
<div
|
|
class="offcanvas offcanvas-end"
|
|
tabindex="-1"
|
|
id="offcanvasEditSection"
|
|
aria-labelledby="offcanvasEditSectionLabel">
|
|
<div class="offcanvas-header border-bottom">
|
|
<h5 id="offcanvasEditSectionLabel" class="offcanvas-title">Edit Section</h5>
|
|
<button
|
|
type="button"
|
|
class="btn-close text-reset"
|
|
data-bs-dismiss="offcanvas"
|
|
aria-label="Tutup"></button>
|
|
</div>
|
|
<div class="offcanvas-body mx-0 flex-grow-0 p-6 h-100">
|
|
<form class="pt-0" id="editSectionForm" action="{{ route('tabel.formulir.update', [$tabel->id, ':id']) }}" method="POST">
|
|
@csrf
|
|
@method('PUT')
|
|
|
|
<input type="hidden" id="edit-section-id" name="id" />
|
|
<input type="hidden" id="edit-section-tipe" name="tipe" value="form-section" />
|
|
<div class="mb-6 form-control-validation">
|
|
<label class="form-label" for="edit-section-label">Label Section</label>
|
|
<input type="text" class="form-control" id="edit-section-label" name="section_label" placeholder="Cth: Nama Petani" />
|
|
</div>
|
|
|
|
<button type="submit" class="btn btn-success me-3 data-submit">Simpan</button>
|
|
<button type="reset" class="btn btn-label-danger" data-bs-dismiss="offcanvas">Batal</button>
|
|
</form>
|
|
</div>
|
|
</div>
|
|
|
|
@push('scripts')
|
|
<script>
|
|
$(document).ready(function() {
|
|
|
|
const offcanvasEditSection = new bootstrap.Offcanvas(document.getElementById('offcanvasEditSection'));
|
|
$('.edit-section').click(function(e) {
|
|
console.log('edit section');
|
|
e.preventDefault();
|
|
const id = $(this).data('id');
|
|
$.get("{{ route('tabel.formulir.show', [$tabel->id, ':id']) }}".replace(':id', id), function (res) {
|
|
if (res.status !== 'success') {
|
|
return;
|
|
}
|
|
$('#edit-section-id').val(res.data.id);
|
|
$('#edit-section-label').val(res.data.section_label);
|
|
offcanvasEditSection.show();
|
|
}).fail(function (xhr) {
|
|
Swal.fire({ icon: 'error', title: 'Gagal!', text: xhr.responseJSON?.message || 'Error' });
|
|
});
|
|
});
|
|
$('#editSectionForm').validate({
|
|
rules: {
|
|
section_label: { required: true }
|
|
},
|
|
messages: {
|
|
section_label: { required: "Label wajib diisi" }
|
|
},
|
|
submitHandler: function (form) {
|
|
$.ajax({
|
|
url: $(form).attr('action').replace(':id', $('#edit-section-id').val()),
|
|
type: 'PUT',
|
|
data: $(form).serialize(),
|
|
success: function () {
|
|
offcanvasEditSection.hide();
|
|
form.reset();
|
|
Swal.fire({ icon: 'success', title: 'Berhasil!', showConfirmButton: false, timer: 1500 })
|
|
.then(() => window.location.reload());
|
|
},
|
|
error: function (xhr) {
|
|
Swal.fire({ icon: 'error', title: 'Gagal!', text: xhr.responseJSON?.message || 'Error' });
|
|
}
|
|
});
|
|
},
|
|
errorElement: 'div',
|
|
errorPlacement: function (error, element) {
|
|
error.addClass('invalid-feedback');
|
|
element.closest('.mb-6, .form-control-validation').append(error);
|
|
},
|
|
highlight: function (element) {
|
|
$(element).addClass('is-invalid');
|
|
},
|
|
unhighlight: function (element) {
|
|
$(element).removeClass('is-invalid');
|
|
}
|
|
});
|
|
});
|
|
</script>
|
|
@endpush |