🐛 fix(currency): perbaiki thousand separator pada input currency dinamis
- Gunakan nilai mentah dari DB pada template JS (hapus number_format di JS) - Inisialisasi IMask untuk nilai existing saat loadSavedNPW() - Terapkan IMask pada class .currency dan .currency-format - Tambahkan event blur untuk menjaga format saat edit ulang - Perbaiki parsing nilai luas dengan parseFloat + regex cleaning - Pastikan perhitungan total NPW tetap akurat - Hapus fungsi formatCurrencyValue yang tidak terpakai - Pastikan thousand separator muncul saat load dan input baru
This commit is contained in:
@@ -366,7 +366,7 @@
|
|||||||
class="w-full currency"
|
class="w-full currency"
|
||||||
name="nilai_npw_${npwCounter}_1"
|
name="nilai_npw_${npwCounter}_1"
|
||||||
placeholder="Harga per meter"
|
placeholder="Harga per meter"
|
||||||
value="${npw.nilai_1 || ''}"
|
value="${npw.nilai_1 || '0'}"
|
||||||
oninput="calculateTotal()">
|
oninput="calculateTotal()">
|
||||||
</label>
|
</label>
|
||||||
</div>
|
</div>
|
||||||
@@ -398,10 +398,36 @@
|
|||||||
calculateTotal();
|
calculateTotal();
|
||||||
});
|
});
|
||||||
|
|
||||||
// Tambahkan event listener untuk currency format
|
// Initialize currency formatting for existing values
|
||||||
newNPWRow.querySelectorAll('.currency-format').forEach(input => {
|
newNPWRow.querySelectorAll('.currency').forEach(input => {
|
||||||
input.addEventListener('input', function() {
|
// Apply IMask immediately for existing values
|
||||||
formatCurrency(this);
|
if (input.value && input.value !== '0') {
|
||||||
|
window.IMask(input, {
|
||||||
|
mask: Number,
|
||||||
|
scale: 0,
|
||||||
|
thousandsSeparator: ".",
|
||||||
|
padFractionalZeros: false,
|
||||||
|
normalizeZeros: true,
|
||||||
|
radix: ",",
|
||||||
|
mapToRadix: ["."],
|
||||||
|
autofix: true,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
// Also add blur event for future editing
|
||||||
|
input.addEventListener('blur', function() {
|
||||||
|
if (!this.imask) {
|
||||||
|
window.IMask(this, {
|
||||||
|
mask: Number,
|
||||||
|
scale: 0,
|
||||||
|
thousandsSeparator: ".",
|
||||||
|
padFractionalZeros: false,
|
||||||
|
normalizeZeros: true,
|
||||||
|
radix: ",",
|
||||||
|
mapToRadix: ["."],
|
||||||
|
autofix: true,
|
||||||
|
});
|
||||||
|
}
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -417,7 +443,7 @@
|
|||||||
|
|
||||||
// Panggil fungsi load NPW saat halaman dimuat
|
// Panggil fungsi load NPW saat halaman dimuat
|
||||||
loadSavedNPW();
|
loadSavedNPW();
|
||||||
document.querySelectorAll('.currency-format').forEach(input => {
|
document.querySelectorAll('.currency').forEach(input => {
|
||||||
input.addEventListener('input', function() {
|
input.addEventListener('input', function() {
|
||||||
formatCurrency(this);
|
formatCurrency(this);
|
||||||
});
|
});
|
||||||
@@ -503,7 +529,7 @@
|
|||||||
const outputElement = row.querySelector('input[id^="nilai_npw_"][id$="_2"]');
|
const outputElement = row.querySelector('input[id^="nilai_npw_"][id$="_2"]');
|
||||||
|
|
||||||
if (luasInput && nilaiInput && outputElement) {
|
if (luasInput && nilaiInput && outputElement) {
|
||||||
const luas = parseInput(luasInput.value);
|
const luas = parseFloat(luasInput.value.replace(/[^0-9.]/g, '')) || 0;
|
||||||
const nilai = parseInput(nilaiInput.value);
|
const nilai = parseInput(nilaiInput.value);
|
||||||
const hasil = luas * nilai;
|
const hasil = luas * nilai;
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user