mirror of
https://github.com/coder/coder.git
synced 2026-09-24 15:04:27 +08:00
fix: show inline validation errors for URL-prefilled workspace names (#22347)
## Description
When a workspace name is pre-filled via the `?name=` URL parameter
(embed links), the Formik form did not mark the name field as "touched".
This meant that Yup validation errors (e.g., name too long) were hidden
from the user, and the form would submit to the server, which returned a
generic "Validation failed" error banner instead of a clear inline
message.
## Fix
Include `name` in `initialTouched` when `defaultName` is provided from
the URL, so validation errors display inline immediately — matching the
behavior of manually typed names.
## Changes
- `site/src/pages/CreateWorkspacePage/CreateWorkspacePageView.tsx`:
Modified `initialTouched` to include `{ name: true }` when `defaultName`
is set via URL parameter
Fixes #22346
---------
Co-authored-by: blink-so[bot] <211532188+blink-so[bot]@users.noreply.github.com>
Co-authored-by: Charlie Voiselle <464492+angrycub@users.noreply.github.com>
This commit is contained in:
co-authored by
blink-so[bot]
Charlie Voiselle
parent
bc27274aba
commit
bfc58c8238
@@ -319,6 +319,18 @@ export const WithParameters: Story = {
|
||||
},
|
||||
};
|
||||
|
||||
export const WithTooLongPrefilledName: Story = {
|
||||
args: {
|
||||
defaultName: "this-name-is-way-too-long-and-exceeds-the-limit",
|
||||
},
|
||||
play: async ({ canvasElement }) => {
|
||||
const canvas = within(canvasElement);
|
||||
await expect(
|
||||
canvas.findByText(/Workspace Name cannot be longer than 32 characters/i),
|
||||
).resolves.toBeVisible();
|
||||
},
|
||||
};
|
||||
|
||||
export const WithPresets: Story = {
|
||||
args: {
|
||||
presets: [
|
||||
|
||||
@@ -127,6 +127,9 @@ export const CreateWorkspacePageView: FC<CreateWorkspacePageViewProps> = ({
|
||||
const initialTouched = Object.fromEntries(
|
||||
parameters.filter((p) => autofillByName[p.name]).map((p) => [p.name, true]),
|
||||
);
|
||||
if (defaultName) {
|
||||
initialTouched.name = true;
|
||||
}
|
||||
|
||||
// The form parameters values hold the working state of the parameters that will be submitted when creating a workspace
|
||||
// 1. The form parameter values are initialized from the websocket response when the form is mounted
|
||||
|
||||
Reference in New Issue
Block a user