update form
This commit is contained in:
@@ -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
|
||||
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user