Skip to content

docs(nextjs-ssr): clarify need for HTML name attribute in form submissions #1574

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

jamestrenda
Copy link

add inline comments to client components in next.js server action examples highlighting the need to explicitly set the name attribute on input fields for native POST submissions (e.g. with Next.js Server Actions). This avoids confusion where inputs may otherwise be omitted from formData.

closes #1565

… submissions

add inline comments to client components in next.js server action examples
highlighting the need to explicitly set the name attribute on input fields
for native POST submissions (e.g. with Next.js Server Actions). This avoids
confusion where inputs may otherwise be omitted from formData.

closes TanStack#1565
Copy link
Contributor

@LeCarbonator LeCarbonator left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me! There's just one question, but this is fine to merge IMO.

@@ -293,7 +293,7 @@ export const ClientComp = () => {
return (
<div>
<input
name="age"
name="age" // must explicitly set the name attribute for the POST request
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would it make sense to use name={field.name} instead of a new string? Or is there something users should know about what names to choose for the JSX elements?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, you're absolutely right (I feel like an AI assistant with that response 😄)!

Since we have access to the field object on the render prop, we should definitely use name={field.name} rather than hard-coding the name attribute. That's what I'm doing in my own project in the component that uses useFieldContext, but I forgot we have access to the field object here as well. Good catch!

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sounds good, then! Could you check the whole file for the name prop? Once that's committed, I'll merge. The comment is fine for just the first instance of it imo.

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

Successfully merging this pull request may close these issues.

Clarify name prop usage for inputs and form controls when using Next.js Server Actions
2 participants