Closed dlwagner closed 4 years ago
Update: The form is a bootsrap 4 form. It has one row and two columns. The submit button sits in the first column with the title and description. The category and priority sit in the second column and they are not being picked up on form submit. If I move the submit button to the second column, then the opposite occurs. I do not have a solution for this, yet.
Temporarily resolved: I eliminated the two columns and put everything in one column. I'm now able to access not only the title and description but also the category and priority and successfully creating documents in the DB. This is not the solution, just a temporary solution. Closed for now.
Moved the form(method="POST" action="/newissue")
up above the row and this fixed the problem with only one column of data getting submitted. The form has been reverted back to the two column form.
CLOSED
On "New Issue" form POST, category and priority are undefined. The form POST action succeeds, however, the document that gets created in mongoDB-atlas does not contain the OBJECTIDs for category and priority because they are coming into the POST controller as undefined. Category and Priority drop-down-select boxes are initially populated via the GET route shown below. The POST route controller takes the form data and POSTs back to mongoDB. For some reason the form code is not picking up the "._id" and "name" from the select drop-downs which is necessary in order for the document to be created correctly in the DB.
Console log output:
The routes: `// Get route - home page router.get('/', secured(), index_controller.index);
// POST route - New Issue form router.post('/newissue', secured(), index_controller.create_issue_post);`
The form code (in Pug):
The Model: `const mongoose = require('mongoose'); const { Schema } = mongoose;
const IssueSchema = new Schema({ title: { type: String, required: true, max: 100 }, description: { type: String, required: true, max: 200 }, author: { type: String, }, category: { type: Schema.Types.ObjectId, ref: 'Category', }, priority: { type: Schema.Types.ObjectId, ref: 'Priority', }, assignee: { type: Schema.Types.ObjectId, ref: 'User' }, milestone: { type: Schema.Types.ObjectId, ref: 'Milestone' }, project: { type: Schema.Types.ObjectId, ref: 'Project' }, status: { type: Schema.Types.ObjectId, ref: 'Status', }, });`
The form UI:
Incorrect document in DB (no category or priority):
What a correct document would look like: