[PR #5626] [MERGED] fix(balancers): defer validation errors until touched or save #5936

Closed
opened 2026-11-02 04:05:10 +07:00 by bsakaguchi · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/MHSanaei/3x-ui/pull/5626
Author: @nima1024m
Created: 6/28/2026
Status: ✅ Merged
Merged: 6/28/2026
Merged by: @MHSanaei

Base: main ← Head: fix/balancer-modal-premature-validation


📝 Commits (1)

  • 9366fde fix(balancers): defer validation errors until touched or save

📊 Changes

2 files changed (+77 additions, -7 deletions)

View changed files

📝 frontend/src/pages/xray/balancers/BalancerFormModal.tsx (+19 -7)
➕ frontend/src/test/balancer-form-modal.test.tsx (+58 -0)

📄 Description

Problem

Opening Xray → Balancers → "+ Balancers" showed validation errors ("Tag is required", "Pick at least one outbound") the instant the modal opened, before any user interaction.

Cause

BalancerFormModal ran BalancerFormSchema.safeParse on its empty initial state at mount and bound the Form.Item validateStatus/help directly to the result, so the errors rendered immediately.

Fix

  • Gate inline errors behind per-field touched tracking plus a submitAttempted flag — errors now appear only after a field is touched or the user clicks Create.
  • Drop the always-disabled Create button (matching the sibling RuleFormModal) so a save attempt surfaces the errors.
  • The existing key-based remount in BalancersTab resets the flags on every open, so no useEffect reset is needed.

Testing

  • New regression test frontend/src/test/balancer-form-modal.test.tsx: asserts no errors on fresh open, and that both errors appear only after a save attempt (without calling onConfirm).
  • npm run typecheck, npm run lint, and the full vitest suite (601 tests / 42 files) pass.
  • Manually verified in the running panel.

🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/MHSanaei/3x-ui/pull/5626 **Author:** [@nima1024m](https://github.com/nima1024m) **Created:** 6/28/2026 **Status:** ✅ Merged **Merged:** 6/28/2026 **Merged by:** [@MHSanaei](https://github.com/MHSanaei) **Base:** `main` ← **Head:** `fix/balancer-modal-premature-validation` --- ### 📝 Commits (1) - [`9366fde`](https://github.com/MHSanaei/3x-ui/commit/9366fdeaf98225c800dc847999b82eba3b8c4e6f) fix(balancers): defer validation errors until touched or save ### 📊 Changes **2 files changed** (+77 additions, -7 deletions) <details> <summary>View changed files</summary> 📝 `frontend/src/pages/xray/balancers/BalancerFormModal.tsx` (+19 -7) ➕ `frontend/src/test/balancer-form-modal.test.tsx` (+58 -0) </details> ### 📄 Description ## Problem Opening **Xray → Balancers → "+ Balancers"** showed validation errors ("Tag is required", "Pick at least one outbound") the instant the modal opened, before any user interaction. ## Cause `BalancerFormModal` ran `BalancerFormSchema.safeParse` on its empty initial state at mount and bound the `Form.Item` `validateStatus`/`help` directly to the result, so the errors rendered immediately. ## Fix - Gate inline errors behind per-field `touched` tracking plus a `submitAttempted` flag — errors now appear only after a field is touched or the user clicks **Create**. - Drop the always-disabled Create button (matching the sibling `RuleFormModal`) so a save attempt surfaces the errors. - The existing `key`-based remount in `BalancersTab` resets the flags on every open, so no `useEffect` reset is needed. ## Testing - New regression test `frontend/src/test/balancer-form-modal.test.tsx`: asserts no errors on fresh open, and that both errors appear only after a save attempt (without calling `onConfirm`). - `npm run typecheck`, `npm run lint`, and the full `vitest` suite (601 tests / 42 files) pass. - Manually verified in the running panel. --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
bsakaguchi 2026-11-02 04:05:10 +07:00
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
MHSanaei/3x-ui#5936
No description provided.