77 lines
3.0 KiB
PHP
77 lines
3.0 KiB
PHP
<div
|
|
class="offcanvas offcanvas-end"
|
|
tabindex="-1"
|
|
id="offcanvasAddSection"
|
|
aria-labelledby="offcanvasAddSectionLabel">
|
|
<div class="offcanvas-header border-bottom">
|
|
<h5 id="offcanvasAddSectionLabel" class="offcanvas-title">Tambah 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="add-new-section pt-0" id="addSectionForm" action="{{ route('tabel.formulir.store', $tabel->id) }}" method="POST">
|
|
@csrf
|
|
|
|
<input type="hidden" id="add-section-tipe" name="tipe" value="form-section" />
|
|
<div class="mb-6 form-control-validation">
|
|
<label class="form-label" for="add-section-label">Label Section</label>
|
|
<input type="text" class="form-control" id="add-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 offcanvasAddSection = new bootstrap.Offcanvas(document.getElementById('offcanvasAddSection'));
|
|
$('#addSectionForm').validate({
|
|
rules: {
|
|
section_label: { required: true }
|
|
},
|
|
messages: {
|
|
section_label: { required: "Label wajib diisi" }
|
|
},
|
|
submitHandler: function (form) {
|
|
$.ajax({
|
|
url: $(form).attr('action'),
|
|
type: 'POST',
|
|
data: $(form).serialize(),
|
|
success: function () {
|
|
offcanvasAddSection.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');
|
|
}
|
|
});
|
|
|
|
$('.add-section').click(function(e) {
|
|
e.preventDefault();
|
|
offcanvasAddSection.show();
|
|
});
|
|
});
|
|
</script>
|
|
@endpush |