change some code in the Build-Checkboxes function

This commit is contained in:
2025-05-26 21:30:59 -04:00
parent 7d53002feb
commit 23a711043b

View File

@@ -268,12 +268,9 @@ function Build-Checkboxes {
Where-Object Page -EQ $Page | Where-Object Page -EQ $Page |
Where-Object Column -EQ $Column | Where-Object Column -EQ $Column |
ForEach-Object { ForEach-Object {
# 1) render the main checkbox
$html = "<label><input type='checkbox' id='$($_.Id)' name='$($_.Name)' data-column='$Column'> $($_.Label)</label>" $html = "<label><input type='checkbox' id='$($_.Id)' name='$($_.Name)' data-column='$Column'> $($_.Label)</label>"
# 2) if this task has SubOptions, render them in a hidden container
if ($_.SubOptions) { if ($_.SubOptions) {
Write-Host "👉 Rendering SubOptions for task $($_.Id)" Write-Host "👉 Rendering SubOptions for task $($_.Id)"
$subHtml = ( $subHtml = (
@@ -285,26 +282,27 @@ function Build-Checkboxes {
) -join "`n" ) -join "`n"
$html += @" $html += @"
<div id='${($_.Id)}OptionsContainer' style='display:none; margin-top:4px;'> <div id='${($_.Id)}OptionsContainer' style='display:none; margin-top:4px;'>
$subHtml $subHtml
</div> </div>
<script> <script>
document.addEventListener('DOMContentLoaded', function () { document.addEventListener('DOMContentLoaded', function () {
const masterCheckbox = document.getElementById('${($_.Id)}'); const masterCheckbox = document.getElementById('${($_.Id)}');
const container = document.getElementById('${($_.Id)}OptionsContainer'); const container = document.getElementById('${($_.Id)}OptionsContainer');
if (masterCheckbox && container) { if (masterCheckbox && container) {
const subCheckboxes = container.querySelectorAll('input[type="checkbox"]');
masterCheckbox.addEventListener('change', function () { masterCheckbox.addEventListener('change', function () {
container.style.display = this.checked ? 'block' : 'none'; container.style.display = this.checked ? 'block' : 'none';
subCheckboxes.forEach(cb => cb.checked = this.checked);
}); });
// Auto-show if already checked (e.g. page reload with checkbox checked)
if (masterCheckbox.checked) { if (masterCheckbox.checked) {
container.style.display = 'block'; container.style.display = 'block';
subCheckboxes.forEach(cb => cb.checked = true);
} }
} }
}); });
</script> </script>
"@ "@
} }
$html $html
@@ -314,6 +312,7 @@ function Build-Checkboxes {
function Get-UIHtml { function Get-UIHtml {
param([string]$Page = 'onboard') param([string]$Page = 'onboard')