Closed brendinsgit closed 11 months ago
change your e.target.species to e.target.name. This refers to the name field on your form that all your form inputs have
I still can't enter anything into the form input except for the size. For some reason it lets me type 1 letter 'e' in there
Show your code for the form
import { Form, Button, Container } from 'react-bootstrap'
const FishForm = (props) => {
const { fish, handleChange, handleSubmit, heading } = props
return (
<Container className="justify-content-center">
<h3>{heading}</h3>
<Form onSubmit={handleSubmit}>
<Form.Group className="m-2">
<Form.Label>Species:</Form.Label>
<Form.Control
placeholder="What is your fish's species?"
id="species"
species="species"
value={ fish.species }
onChange={handleChange}
/>
</Form.Group>
<Form.Group className="m-2">
<Form.Label>Location:</Form.Label>
<Form.Control
placeholder="Where was this fish caught?"
id="location"
species="location"
value={ fish.location }
onChange={handleChange}
/>
</Form.Group>
<Form.Group className="m-2">
<Form.Label>Size:</Form.Label>
<Form.Control
type="number"
placeholder="How big is your fish?"
id="size"
species="size"
value={ fish.size }
onChange={handleChange}
/>
</Form.Group>
<Button className="m-2" type="submit">Submit</Button>
</Form>
</Container>
)
}
export default FishForm
You need to add a name field to your forms. the name needs to be the fields in your use state so name="species"
for the species input for example
Ok, that part was a little confusing for me. It's letting me change and the submit button seems to be working except I get a 'something went wrong please try again' error when I click on it. I think the issue must be within the same files but I'm stumped on it to be honest
Can you see your post or is it not showing up?
It's not creating the fish it's just giving me a failure message
If you check your backend terminal it should give you some more details on why it's failing
What stack are you using?
(ex: MERN(mongoose + react), DR(django + react), PEN, etc.)
What's the problem you're trying to solve?
trying to type in the form's input area
Post any code you think might be relevant (one fenced block per file)
If you see an error message, post it here. If you don't, what unexpected behavior are you seeing?
What is your best guess as to the source of the problem?
There's an issue somewhere with my onChange I think
What things have you already tried to solve the problem?
I tried changing the variable information in the onChange function but it didn't work
Paste a link to your repository here