enhance UX alerts
This commit is contained in:
@@ -815,7 +815,7 @@
|
||||
let originalText = submitBtn.html();
|
||||
submitBtn.prop('disabled', true).html('<i class="ti tabler-loader fa-spin me-2"></i> Menyimpan...');
|
||||
|
||||
$.ajax({
|
||||
$.ajax({
|
||||
url: $(form).attr('action'),
|
||||
type: "POST",
|
||||
data: formData,
|
||||
@@ -826,8 +826,15 @@
|
||||
'Accept': 'application/json'
|
||||
},
|
||||
success: function(res) {
|
||||
alert('Data lahan berhasil ditambahkan!');
|
||||
window.location.href = "{{ route('petani.index') }}";
|
||||
Swal.fire({
|
||||
icon: 'success',
|
||||
title: 'Berhasil!',
|
||||
text: 'Data lahan berhasil ditambahkan.',
|
||||
showConfirmButton: false,
|
||||
timer: 1500
|
||||
}).then(() => {
|
||||
window.location.href = "{{ route('petani.index') }}";
|
||||
});
|
||||
},
|
||||
error: function(xhr) {
|
||||
submitBtn.prop('disabled', false).html(originalText);
|
||||
@@ -838,15 +845,26 @@
|
||||
$.each(errors, function(key, val) {
|
||||
errorMsg += val[0] + "\n";
|
||||
});
|
||||
alert("Penyimpanan Gagal:\n\n" + errorMsg);
|
||||
|
||||
Swal.fire({
|
||||
icon: 'warning',
|
||||
title: 'Penyimpanan Gagal',
|
||||
text: errorMsg,
|
||||
confirmButtonColor: '#dc3545'
|
||||
});
|
||||
} else {
|
||||
let errorDetail = xhr.responseJSON && xhr.responseJSON.message ? xhr.responseJSON.message : xhr.statusText;
|
||||
alert("Error " + xhr.status + ": " + errorDetail);
|
||||
|
||||
Swal.fire({
|
||||
icon: 'error',
|
||||
title: 'Terjadi Kesalahan',
|
||||
text: "Error " + xhr.status + ": " + errorDetail,
|
||||
confirmButtonColor: '#dc3545'
|
||||
});
|
||||
console.error(xhr.responseText);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
return false;
|
||||
}
|
||||
});
|
||||
|
||||
@@ -836,8 +836,6 @@
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
// FORM VALIDATION & SUBMIT
|
||||
$('#petani-lahan-tanaman').validate({
|
||||
rules: {
|
||||
luas_lahan: { required: true },
|
||||
@@ -884,8 +882,8 @@
|
||||
submitBtn.prop('disabled', true).html('<i class="ti tabler-loader fa-spin me-2"></i> Menyimpan...');
|
||||
|
||||
$.ajax({
|
||||
url: $(form).attr('action'),
|
||||
type: "POST",
|
||||
url: $(form).attr('action'),
|
||||
type: "POST",
|
||||
data: formData,
|
||||
processData: false,
|
||||
contentType: false,
|
||||
@@ -894,8 +892,15 @@
|
||||
'Accept': 'application/json'
|
||||
},
|
||||
success: function(res) {
|
||||
alert('Data lahan berhasil disimpan!');
|
||||
window.location.href = "{{ route('petani.index') }}";
|
||||
Swal.fire({
|
||||
icon: 'success',
|
||||
title: 'Berhasil!',
|
||||
text: 'Data lahan berhasil disimpan.',
|
||||
showConfirmButton: false,
|
||||
timer: 1500
|
||||
}).then(() => {
|
||||
window.location.href = "{{ route('petani.index') }}";
|
||||
});
|
||||
},
|
||||
error: function(xhr) {
|
||||
submitBtn.prop('disabled', false).html(originalText);
|
||||
@@ -906,10 +911,22 @@
|
||||
$.each(errors, function(key, val) {
|
||||
errorMsg += val[0] + "\n";
|
||||
});
|
||||
alert("Penyimpanan Gagal:\n\n" + errorMsg);
|
||||
|
||||
Swal.fire({
|
||||
icon: 'warning',
|
||||
title: 'Penyimpanan Gagal',
|
||||
text: errorMsg,
|
||||
confirmButtonColor: '#dc3545'
|
||||
});
|
||||
} else {
|
||||
let errorDetail = xhr.responseJSON && xhr.responseJSON.message ? xhr.responseJSON.message : xhr.statusText;
|
||||
alert("Error " + xhr.status + ": " + errorDetail);
|
||||
|
||||
Swal.fire({
|
||||
icon: 'error',
|
||||
title: 'Terjadi Kesalahan',
|
||||
text: "Error " + xhr.status + ": " + errorDetail,
|
||||
confirmButtonColor: '#dc3545'
|
||||
});
|
||||
console.error(xhr.responseText);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user