GithubHelp home page GithubHelp logo

forms-management's Issues

onSubmit fn in RegistrationForm file doesn't match video

Hey @jherr , thank you for the great tutorial about form management. I learned a ton!
I was reviewing the code attached to the lesson Implement a Server Action for Handling Form Data and I noticed that in Github the onSubmit on the <form .../> is different to what I see on the video. Maybe a typo?

What I see on your video:

image

But what I have on Github is:

image

https://github.com/ProNextJS/forms-management/blob/main/src/app/RegistrationForm.tsx#L95C6-L100C11

Error: Manual Form Submit

Issue Title:
Error: Form Submit

Description:
After adding the useFormState hook and switching to manual form submission using formRef, I encountered issues with the functionality: time to time, I get the error (attached screenshot)

Expected Behavior:
We can workaround it using client and react-hook-form in such way:

	const form = useForm<FormValues>({
		resolver: zodResolver(schema),
		defaultValues: {
			email: '',
			password: '',
			confirmEmail: '',
		},
	});
	const {
		formState: { errors },
	} = form;

	const onSubmit = async (data: FormValues) => {
		const response = await signUpAction(data);

		if (response.error) {
			form.setError('root.serverError', {
				type: '400',
				message: response.message,
			});
		}
	};
    
      // and view (JSX)
      	{errors.root?.['serverError'] && (
		<HelperText className="my-4 text-center" variant="error">
			<b>Server Error: </b>
			{errors.root?.['serverError'].message}
		</HelperText>
	)}

But your version is elegant and much better.

Actual Behavior:
Screenshot with error attached.
It happens here

	<form
		action={formAction}
		className="flex flex-col gap-y-28"
		onSubmit={form.handleSubmit(() => formRef?.current?.submit())} // <=== Here. 
		ref={formRef}
	>

Link to place in repo https://github.com/ProNextJS/forms-management/blob/main/src/app/RegistrationForm.tsx#L95C8-L95C71
Recommendations in Error stack trace also don't work :(

Have you come across such issue?

Screenshots (if applicable):
Screenshot 2024-04-11 at 1 10 00 PM

Additional Information:
Operating System: macOS Sonoma 14.4.1
Browser/Software Version: Google Chrome Version 123.0.6312.87

Code typo on async validation lesson

Thanks for putting this together! I’ve got my whole team working through the course this week 💪

When taking the course myself, I noticed a small typo in the lesson text of the “Implement Async Server-Side Validation” chapter:

https://www.pronextjs.dev/tutorials/forms-management-with-next-js-app-router/forms/implement-async-server-side-validation#building-a-zip-code-validator

In the following code block,

"use server";

export async function validateZipCode(zipCode: string): Promise<boolean> {
  console.log("validateZipcode on SERVER", zipCode)
  return /^/d{5}.test(zipCode) && zipCode.startsWith('9');
}

/^/d{5}.test(zipCode) should be /^\d{5}/.test(zipCode) instead. The original code causes a syntax error crash when used.

Also, validateZipcode.ts is duplicated as validateZipcode.tsx in the repository. There should be only be the .ts one, right?

Thanks again! We’re excited to put this pattern into development ✨

file input form?

Thanks so much for the great tutorial.
Would it be possible to show an example of an input of type="file"?
My attempt give the following error:
Type '{ onChange: (...event: any[]) => void; onBlur: Noop; value: File; disabled?: boolean | undefined; name: "file"; ref: RefCallBack; placeholder: string; accept: string; type: "file"; }' is not assignable to type 'InputProps'. Types of property 'value' are incompatible. Type 'File' is not assignable to type 'string | number | readonly string[] | undefined'.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.