There is an edit page where a user can, obviously, edit aspects of an event. Everything displays fine except the Date shows empty.
I am using the type="date"
in my html which may be a cause, how can I get around this so that I can show the date, because when it saves it saves as null after editing the event
View:
<div class="form-group">
<input class="form-control" type="date" name="editEvent[startDate]" placeholder="Date" value="<%= event.startDate %>">
</div>
Route:
router.get("/event/:id/edit", isLoggedIn, function(req,res){
Event.findById(req.params.id, function (err, foundEvent) {
if(err){
console.log(err);
console.log("Cannot find the event...maybe the database isnt running?")
} else {
res.render("eventEdit", {event: foundEvent});
Everything works fine but the date
Can you add some more information to the question? at the moment it looks quite unclear. like how is your server set up.
It turns out its an HTML thing, if you want to display a date you have to have it formattted as
YYYY-MM-DD
then it shows fine, otherwise it doenst recognize the format.This comes into account if you use the
type="date"
attribute in your inputI had to edit the event date coming from mongo using momentjs and here is the line I used.
var newDate = moment(foundEvent.startDate).utc().format("YYYY-MM-DD") res.render("eventEdit", {event: foundEvent, newDate:newDate});
The
newDate
is the variable being passed to the template, then I just have:This works.