tambahan satuan luas di denah

This commit is contained in:
majid
2025-02-13 13:40:30 +07:00
parent 90249b83e1
commit 5a4c8ab3a4
2 changed files with 42 additions and 7 deletions

View File

@@ -20,7 +20,7 @@
<div class="card-header bg-agi-50"> <div class="card-header bg-agi-50">
<h3 class="card-title">Denah</h3> <h3 class="card-title">Denah</h3>
<div class="flex items-center gap-2"> <div class="flex items-center gap-2">
<a href="{{ route('surveyor.show', ['id' => $permohonan->id ]) }}?form=denah" class="btn btn-xs btn-info"> <a href="{{ route('surveyor.show', ['id' => $permohonan->id]) }}?form=denah" class="btn btn-xs btn-info">
<i class="ki-filled ki-exit-left"></i> Back <i class="ki-filled ki-exit-left"></i> Back
</a> </a>
</div> </div>
@@ -98,7 +98,7 @@
</label> </label>
<input type="text" name="luas_denah[]" <input type="text" name="luas_denah[]"
class="input w-full number-format" class="input w-full number-format"
value="{{ $denah['luas_denah'] ?? '' }}" value="{{ isset($denah['luas_denah']) ? $denah['luas_denah'] . ' m²' : '' }}"
onkeyup="formatNumber(this)"> onkeyup="formatNumber(this)">
</div> </div>
</div> </div>
@@ -191,14 +191,34 @@
input.addEventListener('input', function() { input.addEventListener('input', function() {
formatNumber(this); formatNumber(this);
}); });
input.addEventListener('focus', function() {
if (this.value === 'm²') {
this.setSelectionRange(0, 0); // Kursor di awal
}
});
}); });
// Tambah Denah // Tambah Denah
document.getElementById('tambahDenah').addEventListener('click', function() { document.getElementById('tambahDenah').addEventListener('click', function() {
const denahContainer = document.getElementById('denah-container'); const denahContainer = document.getElementById('denah-container');
const newDenah = createDenahElement(denahIndex); const newDenah = createDenahElement(denahIndex);
denahContainer.appendChild(newDenah); denahContainer.appendChild(newDenah);
denahIndex++; 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 // Event delegation untuk tombol hapus denah
@@ -303,6 +323,12 @@
function submitDenah() { function submitDenah() {
showLoadingSwal('Mengirim data ke server...'); 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 formElement = $('#formDenah')[0];
const formData = new FormData(formElement); const formData = new FormData(formElement);

View File

@@ -26,18 +26,27 @@
} }
function formatNumber(input) { function formatNumber(input) {
let value = input.value.replace(/[^\d.]/g, ''); // Ambil posisi kursor saat ini
input.value = value; 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) { function formatCurrency(value, isDiskon = false) {
// Ensure the value is a valid number // Ensure the value is a valid number
const numericValue = parseFloat(value); const numericValue = parseFloat(value);
if (isNaN(numericValue)) { if (isNaN(numericValue)) {
return 0; return 0;
} }
// Format the number with commas for thousands separators // Format the number with commas for thousands separators