Skip to content

Commit 70968fd

Browse files
committed
Simplify checkbox handling for mirror active field
Removed unnecessary hidden input fields and simplified the form parsing logic for the active checkbox in mirror creation and editing forms. Changes: - Replaced complex list indexing with simple membership check - Removed hidden input fields from both Jinja templates - Updated comments to reflect simpler approach The functionality remains identical, but the code is more readable and maintainable.
1 parent 428c114 commit 70968fd

File tree

3 files changed

+4
-10
lines changed

3 files changed

+4
-10
lines changed

apollo/server/routes/admin_supported_products.py

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -497,10 +497,8 @@ async def admin_supported_product_mirror_new_post(
497497

498498
# Parse form data to get the active field
499499
form_data_raw = await request.form()
500-
# When checkbox is checked: active will be ["false", "true"], take the last value
501-
# When checkbox is unchecked: active will be ["false"], take that value
502-
active_values = form_data_raw.getlist("active")
503-
active_value = active_values[-1] if active_values else "false"
500+
# Checkbox sends "true" when checked, nothing when unchecked
501+
active_value = "true" if "true" in form_data_raw.getlist("active") else "false"
504502

505503
# Validation using centralized validation utility
506504
form_data = {
@@ -602,10 +600,8 @@ async def admin_supported_product_mirror_post(
602600

603601
# Parse form data to get the active field
604602
form_data = await request.form()
605-
# When checkbox is checked: active will be ["false", "true"], take the last value
606-
# When checkbox is unchecked: active will be ["false"], take that value
607-
active_values = form_data.getlist("active")
608-
active_value = active_values[-1] if active_values else "false"
603+
# Checkbox sends "true" when checked, nothing when unchecked
604+
active_value = "true" if "true" in form_data.getlist("active") else "false"
609605

610606
# Validation using centralized validation utility
611607
try:

apollo/server/templates/admin_supported_product_mirror.jinja

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,6 @@
123123
<fieldset class="bx--fieldset">
124124
<legend class="bx--label">Status</legend>
125125
<div class="bx--form-item bx--checkbox-wrapper">
126-
<input type="hidden" name="active" value="false">
127126
<input id="active" name="active" type="checkbox" value="true" class="bx--checkbox"
128127
{% if mirror.active %}checked{% endif %}>
129128
<label for="active" class="bx--checkbox-label">

apollo/server/templates/admin_supported_product_mirror_new.jinja

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,6 @@
112112
<fieldset class="bx--fieldset">
113113
<legend class="bx--label">Status</legend>
114114
<div class="bx--form-item bx--checkbox-wrapper">
115-
<input type="hidden" name="active" value="false">
116115
<input id="active" name="active" type="checkbox" value="true" class="bx--checkbox"
117116
{% if not form_data or form_data.active == 'true' %}checked{% endif %}>
118117
<label for="active" class="bx--checkbox-label">

0 commit comments

Comments
 (0)