Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FormMessage can't be used outside of FormField #2279

Open
mocdaniel opened this issue Jul 16, 2023 · 4 comments · May be fixed by #3044
Open

FormMessage can't be used outside of FormField #2279

mocdaniel opened this issue Jul 16, 2023 · 4 comments · May be fixed by #3044

Comments

@mocdaniel
Copy link

Bug report

Current Behavior

According to the Form documentation I should be able to use a <Form.Message> outside of a wrapping <Form.Field> as long as I wire them up explicitly using the name prop.

However, this doesn't work and results in below error when using with NextJS 13.4.10:

- error node_modules/@radix-ui/react-context/dist/index.mjs (55:0) @ useContext
- error Error: `FormMessage` must be used within `FormField`
null

Expected behavior

I would like to be able to use <Form.Message> outside of a <Form.Field> as mentioned in the docs.

Reproducible example

'use client'

import * as Form from '@radix-ui/react-form'

export default function SignupEmailComponent() {
    return (
        <Form.Root>
            <Form.Message match="valueMissing" name={"email"}>
                Please enter your email address.
            </Form.Message>
            <Form.Message match="typeMismatch" name={"email"}>
                Please enter a valid email address.
            </Form.Message>
            <div className="flex gap-2 items-center">
                <Form.Field className="grow" name="email">
                    <Form.Control asChild>
                        <input type="email" className="w-full" placeholder="[email protected]" required />
                    </Form.Control>
                </Form.Field>
                <Form.Submit asChild>
                    <button className="link-button">Submit</button>
                </Form.Submit>
            </div>
        </Form.Root>
    )
}

Suggested solution

It would be nice to have the component acting as described in the docs.

Your environment

Software Name(s) Version
Radix Package(s) @radix-ui/react-form ^0.0.3
React n/a 18.2.0
Browser Arc (Chromium) 114.0.5735.198
Assistive tech - -
Node n/a 18.16.1
npm/yarn npm 9.5.1
Operating System MacOS 13.4.1(c)
@D4nielJ
Copy link

D4nielJ commented Jul 27, 2023

Same issue here!

@Judx
Copy link

Judx commented Dec 13, 2023

Bump! Same issue here.

@danielterwiel
Copy link

Would like to add that this is supposed to be valid according to the Anatomy

My use-case: I want to display server errors in this Component

@grazianodev
Copy link

This is still an issue, would be great if this is fixed, thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants