Created
June 29, 2025 14:55
-
-
Save bigprof/db223745368b6541325e43d135406b8c to your computer and use it in GitHub Desktop.
Disable fields in detail view form if a checkbox is checked
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$j(() => { | |
// on checking or unchecking the 'Is absent' checkbox, disable/enable fields accordingly | |
$j('#is_abscent').on('change', updateFieldsBasedOnAbsence); | |
setTimeout(updateFieldsBasedOnAbsence, 400); // run after the page is fully loaded | |
}) | |
const updateFieldsBasedOnAbsence = () => { | |
// Change is_abscent to your actual checkbox field name | |
const isAbsent = $j('#is_abscent').is(':checked'); | |
// disable/enable fields based on the absence checkbox | |
// change the names of the fields to match the actual fields you want to disable | |
$j('#nl_from, #nl_to, #dr_from, #dr_to, #mistakes, #warnings, #num_pages') | |
.prop('disabled', isAbsent) | |
.toggleClass('disabled', isAbsent); | |
// the 2 fields below are defined in AppGini as option lists, | |
// so they need special handling via select2 | |
$j('#new_lesson').select2(isAbsent ? 'disable' : 'enable'); | |
$j('#daily_revision').select2(isAbsent ? 'disable' : 'enable'); | |
// 'daily_progress_items' is a child table and we want to disable adding new records is checkbox checked | |
// Change 'daily_progress_items' to actual child table name and 'progress_report' to actual lookup field name | |
// that binds the child table to the parent one. | |
$j('#panel_daily_progress_items-progress_report .btn-success').toggleClass('hidden', isAbsent); | |
// empty the fields if the record is marked as absent | |
if(isAbsent) { | |
// change the field names below to match yours | |
$j('#nl_from, #nl_to, #dr_from, #dr_to, #mistakes, #warnings, #num_pages') | |
.val(''); | |
$j('#new_lesson, #daily_revision').select2('val', ''); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment