diff --git a/resources/views/surveyor/components/denah.blade.php b/resources/views/surveyor/components/denah.blade.php index 7bc8f4d..668ec21 100644 --- a/resources/views/surveyor/components/denah.blade.php +++ b/resources/views/surveyor/components/denah.blade.php @@ -20,7 +20,7 @@

Denah

- + Back
@@ -98,7 +98,7 @@
@@ -191,14 +191,34 @@ input.addEventListener('input', function() { formatNumber(this); }); + input.addEventListener('focus', function() { + if (this.value === 'm²') { + this.setSelectionRange(0, 0); // Kursor di awal + } + }); }); + + // Tambah Denah document.getElementById('tambahDenah').addEventListener('click', function() { const denahContainer = document.getElementById('denah-container'); const newDenah = createDenahElement(denahIndex); denahContainer.appendChild(newDenah); denahIndex++; + + const newInputs = newDenah.querySelectorAll('.number-format'); + newInputs.forEach(input => { + input.addEventListener('input', function() { + formatNumber(this); + }); + + input.addEventListener('focus', function() { + if (this.value === 'm²') { + this.setSelectionRange(0, 0); // Kursor di awal + } + }); + }); }); // Event delegation untuk tombol hapus denah @@ -303,6 +323,12 @@ function submitDenah() { showLoadingSwal('Mengirim data ke server...'); + document.querySelectorAll('.number-format').forEach(input => { + if (input.value.includes('m²')) { + input.value = input.value.replace('m²', '').trim(); + } + }); + const formElement = $('#formDenah')[0]; const formData = new FormData(formElement); diff --git a/resources/views/surveyor/js/utils.blade.php b/resources/views/surveyor/js/utils.blade.php index 30c9ec6..9fcb130 100644 --- a/resources/views/surveyor/js/utils.blade.php +++ b/resources/views/surveyor/js/utils.blade.php @@ -26,18 +26,27 @@ } - function formatNumber(input) { - let value = input.value.replace(/[^\d.]/g, ''); - input.value = value; - } + // Ambil posisi kursor saat ini + const cursorPosition = input.selectionStart; + + // Ambil nilai input tanpa "m²" dan karakter non-angka + let value = input.value.replace(/[^\d]/g, ''); + + // Update nilai input dengan format angka dan "m²" + input.value = value ? value + ' m²' : 'm²'; + + // Atur posisi kursor di depan "m²" + input.setSelectionRange(cursorPosition, cursorPosition); +} + function formatCurrency(value, isDiskon = false) { // Ensure the value is a valid number const numericValue = parseFloat(value); if (isNaN(numericValue)) { - return 0; + return 0; } // Format the number with commas for thousands separators