form tabel
This commit is contained in:
@@ -0,0 +1,94 @@
|
||||
<div
|
||||
class="offcanvas offcanvas-end"
|
||||
tabindex="-1"
|
||||
id="offcanvasEditColumn"
|
||||
aria-labelledby="offcanvasEditColumnLabel">
|
||||
<div class="offcanvas-header border-bottom">
|
||||
<h5 id="offcanvasEditColumnLabel" class="offcanvas-title">Edit Kolom</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="editColumnForm" action="{{ route('tabel.formulir.update', [$tabel->id, ':id']) }}" method="POST">
|
||||
@csrf
|
||||
@method('PUT')
|
||||
|
||||
<input type="hidden" id="edit-column-id" name="id" />
|
||||
<input type="hidden" id="edit-column-tipe" name="tipe" value="form-column" />
|
||||
<input type="hidden" id="edit-column-parent" name="parent_id" value="" />
|
||||
|
||||
<div class="mb-6 form-control-validation">
|
||||
<label class="form-label" for="edit-column-width">Lebar Kolom (1-12)</label>
|
||||
<input type="number" min="1" max="12" step="1" value="3"
|
||||
class="form-control" id="edit-column-width" name="column_width" placeholder="Cth: 3" />
|
||||
</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 offcanvasEditColumn = new bootstrap.Offcanvas(document.getElementById('offcanvasEditColumn'));
|
||||
$('.edit-column').click(function(e) {
|
||||
console.log('edit column');
|
||||
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-column-id').val(res.data.id);
|
||||
$('#edit-column-parent').val(res.data.parent_id);
|
||||
$('#edit-column-width').val(res.data.column_width);
|
||||
offcanvasEditColumn.show();
|
||||
}).fail(function (xhr) {
|
||||
Swal.fire({ icon: 'error', title: 'Gagal!', text: xhr.responseJSON?.message || 'Error' });
|
||||
});
|
||||
});
|
||||
$('#editColumnForm').validate({
|
||||
rules: {
|
||||
column_width: { required: true, number: true },
|
||||
},
|
||||
messages: {
|
||||
column_width: { required: "Lebar kolom wajib diisi" },
|
||||
},
|
||||
submitHandler: function (form) {
|
||||
console.log($('#edit-column-id').val());
|
||||
$.ajax({
|
||||
url: $(form).attr('action').replace(':id', $('#edit-column-id').val()),
|
||||
type: 'PUT',
|
||||
data: $(form).serialize(),
|
||||
success: function () {
|
||||
offcanvasEditColumn.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
|
||||
Reference in New Issue
Block a user