How should you use the Dialog as a form? #399
-
I'm trying to use the Dialog as a form where the The problem is that export default function CreateReview({children, restaurantSlug}) {
const [isOpen, setIsOpen] = useState(false)
const [isSubmitting, setIsSubmitting] = useState(false)
function handleSubmit(e) {
e.preventDefault()
setIsSubmitting(true)
...
}
// isSubmitting blocks the modal from closing
return (
<Root open={isSubmitting || isOpen} onOpenChange={setIsOpen}>
<Trigger>
Leave a Review
</Trigger>
<Overlay />
<Content>
<form onSubmit={handleSubmit}>
...
<Action type="submit" disabled={isSubmitting}>...</Action>
</form>
</Content>
</Root>
)
} This works well-ish but fails for example when one of the fields is required and not filled out (as |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 2 replies
-
Hi @jescowuester, If you're using If so, my first feedback seeing the image above would be that it's probably the wrong component for your use case. Secondly can you help me understand what you are trying to achieve?
I'm not super clear on the use case so that would help. Regardless, if you only wanted a submit button which had nothing to do with your |
Beta Was this translation helpful? Give feedback.
Hi @jescowuester,
If you're using
Action
I am guessing that your are usingAlertDialog
and notDialog
right?If so, my first feedback seeing the image above would be that it's probably the wrong component for your use case.
AlertDialog
should be used basically for things like user confirmation when a destructive action is about to happen, thinks like discard changes, etc. So you probably want to useDialog
instead here.Secondly can you help me understand what you are trying to achieve?
I'm…