Hi!
I have a Node.js CMS application using MongoDB, Mongoose and Express.
There is a page that is collecting user info and pass it to the admin. I got that part done. But I also like to be able to change the status to each applies as admin. Like "in progress", "Denied", and "Approved" and save it to the database using only checkboxes.
My approach is the give each applies three checkboxes and in the model one of them is true the others are false. "In progress" is true default, but if I change it to "approved" the database changes the data and "In progress" is false, and "Approved" becomes true.
I tried many thing but nothing works out.
Can you help me? Thanks!
This is the model:
const {Schema, model} = require('mongoose');
const ApplySchema = new Schema({
firstname: {
type: String,
require: true
},
lastname: {
type: String,
require: true
},
applyStatus : {
"in progress": {
type: Boolean,
default: true
},
"denied": {
type: Boolean,
default: false
},
"approved": {
type: Boolean,
default: false
}
}
});
try {
module.exports = model('applications', ApplySchema);
} catch (e) {
module.exports = model('applications');
}
This is the admin route:
router.get('/', (req, res) => {
Apply.find({})
.then(applications => {
res.render('admin/apply/apply', {applications: applications});
});
});
This is the Handlebars:
</thead>
<tbody>
<tr>
<td></td>
<td></td>
<td>
<div class="form-check">
<input class="form-check-input" type="checkbox" value="" id="flexCheckDefault" checked>
<label class="form-check-label" for="flexCheckDefault">
In progress
</label>
</div>
<div class="form-check">
<input class="form-check-input" type="checkbox" value="" id="flexCheckDefault">
<label class="form-check-label" for="flexCheckDefault">
Denied
</label>
</div>
<div class="form-check">
<input class="form-check-input" type="checkbox" value="" id="flexCheckDefault">
<label class="form-check-label" for="flexCheckDefault">
Approved
</label>
</div>
</td>
</tr>
</tbody>
</table>
</div>
</div>
</div>
Aucun commentaire:
Enregistrer un commentaire