Skip to content

Commit 3f606c7

Browse files
katinthehatsiteKateryna Kodonenko
andauthored
Studio: New site form can be submitted with incorrect values using enter key (#2959)
* Ensure we don't submit form that has empty site name * Solve for sitename errors * Linter fix --------- Co-authored-by: Kateryna Kodonenko <kateryna@automattic.com>
1 parent 140968a commit 3f606c7

1 file changed

Lines changed: 13 additions & 2 deletions

File tree

‎apps/studio/src/modules/add-site/components/create-site-form.tsx‎

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -293,6 +293,7 @@ export const CreateSiteForm = ( {
293293
}
294294

295295
const hasErrors =
296+
! siteName.trim() ||
296297
!! pathError ||
297298
( useCustomDomain && !! customDomainError ) ||
298299
! adminUsername.trim() ||
@@ -306,7 +307,15 @@ export const CreateSiteForm = ( {
306307
onValidityChange( isValid );
307308
}
308309
// eslint-disable-next-line react-hooks/exhaustive-deps
309-
}, [ pathError, customDomainError, useCustomDomain, adminUsername, adminPassword, adminEmail ] );
310+
}, [
311+
siteName,
312+
pathError,
313+
customDomainError,
314+
useCustomDomain,
315+
adminUsername,
316+
adminPassword,
317+
adminEmail,
318+
] );
310319

311320
const handleSiteNameChange = useCallback(
312321
async ( name: string ) => {
@@ -455,7 +464,9 @@ export const CreateSiteForm = ( {
455464
onKeyDown={ ( event ) => {
456465
if ( event.key === 'Enter' ) {
457466
event.preventDefault();
458-
handleFormSubmit( event as FormEvent );
467+
if ( errorCount === 0 ) {
468+
handleFormSubmit( event as FormEvent );
469+
}
459470
}
460471
} }
461472
data-testid="site-name-input"

0 commit comments

Comments
 (0)