Enter key handling & hostname field reset in resource create

This commit is contained in:
Pallavi
2025-09-04 01:10:55 +05:30
parent 122902968f
commit 84fb3add33
2 changed files with 49 additions and 14 deletions

View File

@@ -630,19 +630,29 @@ export default function Page() {
defaultValue={row.original.ip} defaultValue={row.original.ip}
className="min-w-[150px]" className="min-w-[150px]"
onBlur={(e) => { onBlur={(e) => {
const parsed = parseHostTarget(e.target.value); const input = e.target.value.trim();
const hasProtocol = /^(https?|h2c):\/\//.test(input);
const hasPort = /:\d+(?:\/|$)/.test(input);
if (parsed) { if (hasProtocol || hasPort) {
updateTarget(row.original.targetId, { const parsed = parseHostTarget(input);
...row.original, if (parsed) {
method: parsed.protocol, updateTarget(row.original.targetId, {
ip: parsed.host, ...row.original,
port: parsed.port ? Number(parsed.port) : undefined, method: hasProtocol ? parsed.protocol : row.original.method,
}); ip: parsed.host,
port: hasPort ? parsed.port : row.original.port
});
} else {
updateTarget(row.original.targetId, {
...row.original,
ip: input
});
}
} else { } else {
updateTarget(row.original.targetId, { updateTarget(row.original.targetId, {
...row.original, ...row.original,
ip: e.target.value, ip: input
}); });
} }
}} }}
@@ -744,6 +754,11 @@ export default function Page() {
<SettingsSectionForm> <SettingsSectionForm>
<Form {...baseForm}> <Form {...baseForm}>
<form <form
onKeyDown={(e) => {
if (e.key === "Enter") {
e.preventDefault(); // block default enter refresh
}
}}
className="space-y-4" className="space-y-4"
id="base-resource-form" id="base-resource-form"
> >
@@ -856,6 +871,11 @@ export default function Page() {
<SettingsSectionForm> <SettingsSectionForm>
<Form {...tcpUdpForm}> <Form {...tcpUdpForm}>
<form <form
onKeyDown={(e) => {
if (e.key === "Enter") {
e.preventDefault(); // block default enter refresh
}
}}
className="space-y-4" className="space-y-4"
id="tcp-udp-settings-form" id="tcp-udp-settings-form"
> >
@@ -1204,11 +1224,21 @@ export default function Page() {
id="ip" id="ip"
{...field} {...field}
onBlur={(e) => { onBlur={(e) => {
const parsed = parseHostTarget(e.target.value); const input = e.target.value.trim();
if (parsed) { const hasProtocol = /^(https?|h2c):\/\//.test(input);
addTargetForm.setValue("method", parsed.protocol); const hasPort = /:\d+(?:\/|$)/.test(input);
addTargetForm.setValue("ip", parsed.host);
addTargetForm.setValue("port", parsed.port); if (hasProtocol || hasPort) {
const parsed = parseHostTarget(input);
if (parsed) {
if (hasProtocol || !addTargetForm.getValues("method")) {
addTargetForm.setValue("method", parsed.protocol);
}
addTargetForm.setValue("ip", parsed.host);
if (hasPort || !addTargetForm.getValues("port")) {
addTargetForm.setValue("port", parsed.port);
}
}
} else { } else {
field.onBlur(); field.onBlur();
} }

View File

@@ -620,6 +620,11 @@ WantedBy=default.target`
<SettingsSectionForm> <SettingsSectionForm>
<Form {...form}> <Form {...form}>
<form <form
onKeyDown={(e) => {
if (e.key === "Enter") {
e.preventDefault(); // block default enter refresh
}
}}
className="space-y-4" className="space-y-4"
id="create-site-form" id="create-site-form"
> >