Skip to content

fix: Switch/toggle fields never trigger form auto-save - #1420

Open
xtantaudio wants to merge 1 commit into
meshtastic:mainfrom
xtantaudio:fix/toggle-switch-not-triggering-save
Open

fix: Switch/toggle fields never trigger form auto-save#1420
xtantaudio wants to merge 1 commit into
meshtastic:mainfrom
xtantaudio:fix/toggle-switch-not-triggering-save

Conversation

@xtantaudio

@xtantaudio xtantaudio commented Aug 31, 2026

Copy link
Copy Markdown

Problem

Toggle switches throughout the app (Region, MQTT enabled, Bluetooth, channel uplink/downlink, etc.) appear to save when clicked, but the change is never actually submitted to the device. The Switch component's onCheckedChange only updates local React state — it doesn't produce anything the form's auto-save-on-change wiring is listening for, so the value change never triggers a submit.

Fix

Added explicit save-trigger wiring (formAutoSave.ts, updates to DynamicForm.tsx) so a toggle click reliably fires the same submit path as any other form field change.

Verification

  • New test confirms a toggle click now fires exactly one save with the correct value, in both directions (on and off).
  • Verified live against real meshtasticd hardware — a toggle change that previously never reached the device (confirmed via daemon logs showing zero outgoing packets) now correctly transmits and persists (confirmed via the device's own raw protobuf output on disk).

Summary by CodeRabbit

  • New Features

    • Custom toggle controls now trigger form auto-save reliably, including keyboard interactions.
    • Added support for automatic saving from non-native form controls.
    • Validation failures during save now identify the invalid fields.
  • Bug Fixes

    • Prevented duplicate saves when toggling custom controls.
    • Ensured toggles work safely when auto-save is unavailable.

@vercel

vercel Bot commented Aug 31, 2026

Copy link
Copy Markdown

Someone is attempting to deploy a commit to the Meshtastic Team on Vercel.

A member of the Team first needs to authorize it.

@coderabbitai

coderabbitai Bot commented Aug 31, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 9664071d-0923-40cf-b287-c49a76aae4b5

📥 Commits

Reviewing files that changed from the base of the PR and between cffd35f and feda27c.

📒 Files selected for processing (4)
  • apps/web/src/components/Form/DynamicForm.tsx
  • apps/web/src/components/Form/FormToggle.test.tsx
  • apps/web/src/components/Form/FormToggle.tsx
  • apps/web/src/components/Form/formAutoSave.ts

Included review availability: Your plan provides up to 4 included reviews per hour; 3 remain after this review.


📝 Walkthrough

Walkthrough

DynamicForm now reports blocked validation saves and exposes an imperative auto-save callback. ToggleInput uses this callback for non-native switch changes while preventing duplicate submissions. Tests cover mouse, keyboard, native input, context, and missing-callback behavior.

Changes

Form auto-save flow

Layer / File(s) Summary
Auto-save context and form wiring
apps/web/src/components/Form/formAutoSave.ts, apps/web/src/components/Form/DynamicForm.tsx
DynamicForm provides autoSave for submitType="onChange" forms. It reports invalid field keys when validation blocks submission.
Toggle auto-save behavior
apps/web/src/components/Form/FormToggle.tsx, apps/web/src/components/Form/FormToggle.test.tsx
ToggleInput triggers auto-save after switch changes and stops propagation to avoid duplicate saves. Tests cover mouse, keyboard, native input, context, and missing-callback behavior.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Merge Risk: 🔵 Low · up to feda2

Toggle changes now autosave through the existing configuration path, but a rejected validation can leave the displayed toggle out of sync with the device configuration when the related error is not visible. The PR is mergeable with explicit owner awareness and follow-up to surface failed saves clearly.

Sequence Diagram(s)

sequenceDiagram
  participant User
  participant ToggleInput
  participant DynamicForm
  participant onSubmit
  User->>ToggleInput: Toggle switch
  ToggleInput->>DynamicForm: Invoke autoSave
  DynamicForm->>DynamicForm: Validate and submit
  DynamicForm->>onSubmit: Pass updated form values
Loading

Poem

A rabbit flips a switch with care
The form sends fresh values through the air
Invalid fields now speak aloud
Duplicate saves stay unallowed
Tests hop through keys and clicks
Auto-save handles custom tricks

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 20.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 5 functions across 4 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and concisely identifies the main change: fixing switch and toggle fields that fail to trigger form auto-save.
Description check ✅ Passed The description clearly explains the problem, the implementation, and verification results. It omits several template sections, including Related Issues, Changes Made, Screenshots, and Checklist, but …
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Full details: Description check

Explanation

The description clearly explains the problem, the implementation, and verification results. It omits several template sections, including Related Issues, Changes Made, Screenshots, and Checklist, but it contains the critical information needed to understand and review the change.

  • Fix all pre-merge checks with AI
✨ Finishing Touches 💡 1
🛠️ Fix failing CI checks 💡
  • Create stacked PR
  • Commit on current branch

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@CLAassistant

CLAassistant commented Aug 31, 2026

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

@xtantaudio
xtantaudio force-pushed the fix/toggle-switch-not-triggering-save branch from feda27c to be03324 Compare August 31, 2026 03:10
Toggle switches throughout the app (Region, MQTT enabled, Bluetooth,
channel uplink/downlink, etc.) appeared to save when clicked, but the
change was never actually submitted to the device. The Switch
component's onCheckedChange only updated local React state - it never
produced anything that the form's auto-save-on-change wiring was
listening for, so the value change never triggered a submit.

Added explicit save-trigger wiring (formAutoSave.ts, DynamicForm.tsx)
so a toggle click reliably fires the same submit path as any other
form field change.

Verified: new test confirms a toggle click now fires exactly one save
with the correct value, in both directions (on and off).
@xtantaudio
xtantaudio force-pushed the fix/toggle-switch-not-triggering-save branch from be03324 to ee7ae73 Compare August 31, 2026 03:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants