From 1335859b0d3f76db8bf7ae45fef706839f9b3d5b Mon Sep 17 00:00:00 2001 From: Lee Peuker Date: Tue, 5 Jul 2022 18:52:04 +0200 Subject: [PATCH] Add default current date when logging movie --- public/js/logMovie.js | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/public/js/logMovie.js b/public/js/logMovie.js index fedcd5bb..a26be4a8 100644 --- a/public/js/logMovie.js +++ b/public/js/logMovie.js @@ -3,13 +3,22 @@ const datepicker = new Datepicker(document.getElementById('watchDate'), { title: 'Watch date', }) +function getCurrentDate () { + const today = new Date() + const dd = String(today.getDate()).padStart(2, '0') + const mm = String(today.getMonth() + 1).padStart(2, '0') //January is 0! + const yyyy = today.getFullYear() + + return dd + '.' + mm + '.' + yyyy +} + const watchModal = document.getElementById('watchDateModal') watchModal.addEventListener('show.bs.modal', async function (e) { let movieId = e.relatedTarget.id let movieTitle = document.getElementById(movieId + '_movieTitle').value let movieYear = document.getElementById(movieId + '_movieReleaseYear').value - document.getElementById('watchDate').value = '' + document.getElementById('watchDate').value = getCurrentDate() document.getElementById('tmdbId').value = movieId document.getElementById('watchDateModalTitle').innerHTML = movieTitle + ' (' + movieYear + ')' let ratingNumber = await fetchRating(movieId)