56 lines
1.4 KiB
PHP
56 lines
1.4 KiB
PHP
<script>
|
|
function showLoadingSwal(message) {
|
|
Swal.fire({
|
|
title: message,
|
|
allowOutsideClick: false,
|
|
didOpen: () => {
|
|
Swal.showLoading();
|
|
}
|
|
});
|
|
}
|
|
|
|
function hideLoadingSwal() {
|
|
Swal.close();
|
|
}
|
|
|
|
function previewImage(input, imageId) {
|
|
const preview = document.getElementById(imageId);
|
|
if (input.files && input.files[0]) {
|
|
const reader = new FileReader();
|
|
reader.onload = function(e) {
|
|
preview.src = e.target.result;
|
|
preview.classList.remove('hidden');
|
|
}
|
|
reader.readAsDataURL(input.files[0]);
|
|
}
|
|
}
|
|
|
|
|
|
|
|
function formatNumber(input) {
|
|
let value = input.value.replace(/[^\d.]/g, '');
|
|
input.value = value;
|
|
}
|
|
|
|
|
|
function formatCurrency(value) {
|
|
if (!value) return '';
|
|
|
|
// Jika input adalah elemen, ambil nilainya
|
|
const numericValue = typeof value === 'string' ? value : value.value;
|
|
|
|
// Hapus semua karakter non-digit
|
|
const cleanValue = numericValue.toString().replace(/[^\d]/g, '');
|
|
|
|
// Format ke currency
|
|
const formattedValue = new Intl.NumberFormat('id-ID').format(cleanValue);
|
|
|
|
// Jika input adalah elemen, update nilainya
|
|
if (typeof value !== 'string') {
|
|
value.value = formattedValue;
|
|
}
|
|
|
|
return formattedValue;
|
|
}
|
|
</script>
|