- Read Tutorial
- Watch Guide Video
What we need to do now is just get the data from our form and pass it through here as well. The new request object data. Let's go ahead and go to requestsNew.js. Let's provide these fields in there as the object. Let's say:
requestsNew.js
onSubmit = fields => { // if(button == 'submit') { // // save new newsletter on the backend. perform a post request here. // console.log('trying to submit to backend.'); // } this.props.createNewRequest(this.props._id, fields, () => { this.props.history.push("/dashboard"); }) };
Let's go in here and make sure they're all right. Let's go to requests.js, and let's console.log
it. So let's say:
requests.js
export function createNewRequest(userId, fields, success) { console.log('token: ',localStorage.getItem(token)) console.log('userId: ', userId); console.log('fields ', fields);
Then we should create a new request object. Let's console.log
that, let's go check it out, let's login, let's go to requests, let's hit this plus
button, and let's type something in here. Let's say "My lightbulbs exploded."
It looks like we can't type in the description. Let's just hit submit, and we will handle that in a second. That's probably an error on our form. Let's hit submit. You'll see it has those errors, and then you have our fields.
Let's go get this description working and then let's pass in a description as well. Let's go to our code and go to requestsNew.js, and let's go into our NewNewsletterForm.js. There's probably something wrong with our text-field because we can't type in there.
Okay, so placeholder
, title
, component
, and editValue
. Nothing's working, let's go into formField.js. Now we need to scroll to textarea
and see why this isn't working. Let's try this. Let's put a slash there, and let's get rid of this textarea
and see if this allows us to type in there.
Now, this is why I'm pretty sure. It's not this, but let's try it. Let's reload it and go into New Request
. It's still not working. What we need to do is say on editValue
, if there's no editValue
then let's say input.value
.
Now let's try it. That will hook it back up to Redux-form
. We can type in the description now, so we are all good. Now, let's try that again. Service Request Title is Fix this junk
, and then let's say description ASAP brotha
.
Now, what we'll do is we will also provide an image, but that's with the form data. Let's hit submit. Go up, and you'll see we have both our title and our body. Now what we need to do is get access to our image. The only way to get access to our image is through posting it as form data.
We need to do that in the next video. Let's go ahead and commit our code, and we'll say we fixed this and did a couple other things. Let's say git status
, git add .
, and let's say git commit -m "fixed a couple bugs"
. Then we will finish it in the next video.