Skip to content

Commit

Permalink
Fix ui.inlineCreate for relationships submitting the parent form
Browse files Browse the repository at this point in the history
  • Loading branch information
dcousens committed Nov 15, 2023
1 parent 5a7637b commit f14d5d5
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 7 deletions.
5 changes: 5 additions & 0 deletions .changeset/fix-inline-create.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@keystone-6/core': patch
---

Fix ui.inlineCreate: { ... } for relationships submitting the parent form of nested relationship fields
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/** @jsxRuntime classic */
/** @jsx jsx */

import { type FormEvent, useState } from 'react'
import { useState } from 'react'
import { jsx, Stack } from '@keystone-ui/core'
import isDeepEqual from 'fast-deep-equal'
import { useToasts } from '@keystone-ui/toast'
Expand Down Expand Up @@ -53,11 +53,9 @@ export function InlineCreate ({
})

const invalidFields = useInvalidFields(fields, value)

const [forceValidation, setForceValidation] = useState(false)

const onSubmit = (event: FormEvent<HTMLFormElement>) => {
event.preventDefault()
const onSubmit = () => {
const newForceValidation = invalidFields.size !== 0
setForceValidation(newForceValidation)

Expand Down Expand Up @@ -106,7 +104,7 @@ export function InlineCreate ({
}

return (
<form onSubmit={onSubmit}>
<section>
<Stack gap="xlarge">
{error && (
<GraphQLErrorNotice networkError={error?.networkError} errors={error?.graphQLErrors} />
Expand All @@ -119,14 +117,14 @@ export function InlineCreate ({
value={value}
/>
<Stack gap="small" across>
<Button isLoading={loading} size="small" tone="positive" weight="bold" type="submit">
<Button onClick={onSubmit} isLoading={loading} size="small" tone="positive" weight="bold">
Create {list.singular}
</Button>
<Button size="small" weight="none" onClick={onCancel}>
Cancel
</Button>
</Stack>
</Stack>
</form>
</section>
)
}

0 comments on commit f14d5d5

Please sign in to comment.