Reputation: 3
I am exploring PUG and have an express/mongodb/mongoose backend.
In my Pug update form i have a date field
input#date_of_birth.form-control(type='date' name= 'date_of_birth' value=(author==undefined ? '' : author.date_of_birth))
In express, the following express-validator functions are used to sanitize the date input
body('date_of_birth', 'Invalid Date of Birth').isISO8601().optional({checkFalsy: true}),
sanitizeBody('date_of_birth').toDate(),
The author object passed has date value fetched from mongodb through mongoose model find () and is passed on to the pug form.
eg. { "name":"Joe", "date_of_birth":"2015-01-01T00:00:00.000Z"}
This value is being displayed in a label in the pug form but not in the input date field. So, i am unable to update the date field.
what do i need to do to get the date field to display in the input for modification ?
Upvotes: 0
Views: 220
Reputation: 3
Nevermind. i found the answer. This made it compliant for display in pug. Needs to be in YYYY-MM-DD format.
- let date_of_birth = author.date_of_birth.toISOString().substr(0, 10));
Upvotes: 0