Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitd104cd6

Browse files
authored
fix: display validation error for workspace name (#17564)
- Display form validation error for workspace name- Scroll to the workspace name field if there is a validation error
1 parent6bafe35 commitd104cd6

File tree

1 file changed

+18
-6
lines changed

1 file changed

+18
-6
lines changed

‎site/src/pages/CreateWorkspacePage/CreateWorkspacePageViewExperimental.tsx

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ import {
2828
useContext,
2929
useEffect,
3030
useId,
31+
useRef,
3132
useState,
3233
}from"react";
3334
import{getFormHelpers,nameValidator}from"utils/formUtils";
@@ -103,6 +104,7 @@ export const CreateWorkspacePageViewExperimental: FC<
103104
);
104105
const[showPresetParameters,setShowPresetParameters]=useState(false);
105106
constid=useId();
107+
constworkspaceNameInputRef=useRef<HTMLInputElement>(null);
106108
constrerollSuggestedName=useCallback(()=>{
107109
setSuggestedName(()=>generateWorkspaceName());
108110
},[]);
@@ -140,10 +142,15 @@ export const CreateWorkspacePageViewExperimental: FC<
140142
}
141143
},[error]);
142144

143-
constgetFieldHelpers=getFormHelpers<TypesGen.CreateWorkspaceRequest>(
144-
form,
145-
error,
146-
);
145+
useEffect(()=>{
146+
if(form.submitCount>0&&form.errors){
147+
workspaceNameInputRef.current?.scrollIntoView({
148+
behavior:"smooth",
149+
block:"center",
150+
});
151+
workspaceNameInputRef.current?.focus();
152+
}
153+
},[form.submitCount,form.errors]);
147154

148155
const[presetOptions,setPresetOptions]=useState([
149156
{label:"None",value:""},
@@ -333,16 +340,22 @@ export const CreateWorkspacePageViewExperimental: FC<
333340
<LabelclassName="text-sm"htmlFor={`${id}-workspace-name`}>
334341
Workspace name
335342
</Label>
336-
<div>
343+
<divclassName="flex flex-col">
337344
<Input
338345
id={`${id}-workspace-name`}
346+
ref={workspaceNameInputRef}
339347
value={form.values.name}
340348
onChange={(e)=>{
341349
form.setFieldValue("name",e.target.value.trim());
342350
resetMutation();
343351
}}
344352
disabled={creatingWorkspace}
345353
/>
354+
{form.touched.name&&form.errors.name&&(
355+
<divclassName="text-content-destructive text-xs mt-2">
356+
{form.errors.name}
357+
</div>
358+
)}
346359
<divclassName="flex gap-2 text-xs text-content-secondary items-center">
347360
Need a suggestion?
348361
<Button
@@ -477,7 +490,6 @@ export const CreateWorkspacePageViewExperimental: FC<
477490

478491
return(
479492
<DynamicParameter
480-
{...getFieldHelpers(parameterInputName)}
481493
key={parameter.name}
482494
parameter={parameter}
483495
onChange={(value)=>

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp