Skip to content

Commit 57ef96a

Browse files
authored
fix: swarm health check fields not resetting to default values (Dokploy#4558)
Fixes Dokploy#4553 - Replace z.coerce.number() with a custom transform that converts empty strings to undefined instead of 0 - Add value={field.value ?? ""} to numeric inputs so they visually clear when reset to undefined
1 parent b29a87a commit 57ef96a

1 file changed

Lines changed: 13 additions & 8 deletions

File tree

‎apps/dokploy/components/dashboard/application/advanced/cluster/swarm-forms/health-check-form.tsx‎

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,17 @@ import {
1616
import { Input } from "@/components/ui/input";
1717
import { api } from "@/utils/api";
1818

19+
const optionalNumber = z
20+
.union([z.string(), z.number()])
21+
.transform((val) => (val === "" ? undefined : Number(val)))
22+
.optional();
23+
1924
export const healthCheckFormSchema = z.object({
2025
Test: z.array(z.string()).optional(),
21-
Interval: z.coerce.number().optional(),
22-
Timeout: z.coerce.number().optional(),
23-
StartPeriod: z.coerce.number().optional(),
24-
Retries: z.coerce.number().optional(),
26+
Interval: optionalNumber,
27+
Timeout: optionalNumber,
28+
StartPeriod: optionalNumber,
29+
Retries: optionalNumber,
2530
});
2631

2732
interface HealthCheckFormProps {
@@ -195,7 +200,7 @@ export const HealthCheckForm = ({ id, type }: HealthCheckFormProps) => {
195200
Time between health checks (e.g., 10000000000 for 10 seconds)
196201
</FormDescription>
197202
<FormControl>
198-
<Input type="number" placeholder="10000000000" {...field} />
203+
<Input type="number" placeholder="10000000000" {...field} value={field.value ?? ""} />
199204
</FormControl>
200205
<FormMessage />
201206
</FormItem>
@@ -212,7 +217,7 @@ export const HealthCheckForm = ({ id, type }: HealthCheckFormProps) => {
212217
Maximum time to wait for health check response
213218
</FormDescription>
214219
<FormControl>
215-
<Input type="number" placeholder="10000000000" {...field} />
220+
<Input type="number" placeholder="10000000000" {...field} value={field.value ?? ""} />
216221
</FormControl>
217222
<FormMessage />
218223
</FormItem>
@@ -229,7 +234,7 @@ export const HealthCheckForm = ({ id, type }: HealthCheckFormProps) => {
229234
Initial grace period before health checks begin
230235
</FormDescription>
231236
<FormControl>
232-
<Input type="number" placeholder="10000000000" {...field} />
237+
<Input type="number" placeholder="10000000000" {...field} value={field.value ?? ""} />
233238
</FormControl>
234239
<FormMessage />
235240
</FormItem>
@@ -247,7 +252,7 @@ export const HealthCheckForm = ({ id, type }: HealthCheckFormProps) => {
247252
unhealthy
248253
</FormDescription>
249254
<FormControl>
250-
<Input type="number" placeholder="3" {...field} />
255+
<Input type="number" placeholder="3" {...field} value={field.value ?? ""} />
251256
</FormControl>
252257
<FormMessage />
253258
</FormItem>

0 commit comments

Comments
 (0)