update form

This commit is contained in:
majid
2024-11-27 09:08:04 +07:00
parent 107b1ca590
commit b7a60abd3e
11 changed files with 893 additions and 535 deletions

View File

@@ -70,17 +70,61 @@
@endsection
@push('scripts')
<script type="text/javascript">
function toggleTidakSesuai(field, inputId) {
const selectedValue = $(`[name="${field}"]:checked, [name="${field}"]:checked`).val();
function toggleFieldVisibility(fieldName, inputId, visibleValues = []) {
const selectedValue = $(`[name="${fieldName}"]:checked`).val();
const inputField = $(`#${inputId}`);
if (selectedValue === 'tidak sesuai' || selectedValue === 'lainnya') {
if (visibleValues.includes(selectedValue)) {
inputField.show();
} else {
inputField.hide().val('');
}
}
function toggleCheckboxVisibility(fieldName, inputId, visibleValues = []) {
const selectedValues = $(`[name="${fieldName}[]"]:checked`)
.map(function() {
return $(this).val().toLowerCase(); // Konversi nilai ke huruf kecil
})
.get();
const inputField = $(`#${inputId}`);
// Cek apakah salah satu nilai yang dipilih cocok dengan visibleValues
const shouldShow = visibleValues.some(value => selectedValues.includes(value.toLowerCase()));
if (shouldShow) {
inputField.show();
} else {
inputField.hide().val('');
}
}
function toggleMultipleFields(fieldName, mappings) {
// Ambil semua nilai checkbox yang dicentang
const selectedValues = $(`[name="${fieldName}[]"]:checked`)
.map(function() {
return $(this).val().toLowerCase(); // Konversi nilai ke huruf kecil
})
.get();
// Iterasi melalui setiap mapping
for (const [key, inputId] of Object.entries(mappings)) {
const inputField = $(`#${inputId}`);
// Tampilkan input jika nilai yang relevan dipilih
if (selectedValues.includes(key.toLowerCase())) {
inputField.show();
} else {
inputField.hide().val(''); // Sembunyikan dan reset nilai
}
}
}
function submitData() {
const formElement = $('#formInspeksi')[0];
const formData = new FormData(formElement);
@@ -154,8 +198,10 @@
}
const newElement = template.cloneNode(true);
const inputs = newElement.querySelectorAll('input, textarea');
inputs.forEach(input => (input.value = ''));
const textarea = newElement.querySelector('textarea');
if (textarea) {
textarea.value = '';
}
const deleteButton = newElement.querySelector('.remove-btn');
if (deleteButton) {
@@ -167,3 +213,6 @@
}
</script>
@endpush