From 43020939ed4762da7455451c36a15660799b1ef7 Mon Sep 17 00:00:00 2001 From: Chirag Chhatrala <60499540+chiragchhatrala@users.noreply.github.com> Date: Sat, 11 Mar 2023 16:42:55 +0530 Subject: [PATCH] pre-fill with current date not working with local storage (#96) --- resources/js/components/open/forms/OpenForm.vue | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/resources/js/components/open/forms/OpenForm.vue b/resources/js/components/open/forms/OpenForm.vue index 6c56606..77ed51e 100644 --- a/resources/js/components/open/forms/OpenForm.vue +++ b/resources/js/components/open/forms/OpenForm.vue @@ -330,7 +330,21 @@ export default { pendingData = null } if (pendingData !== null && pendingData) { - this.dataForm = new Form(JSON.parse(pendingData)) + pendingData = JSON.parse(pendingData) + this.fields.forEach((field) => { + if (field.type === 'date' && field.prefill_today === true) { // For Prefill with 'today' + const dateObj = new Date() + let currentDate = dateObj.getFullYear() + '-' + + String(dateObj.getMonth() + 1).padStart(2, '0') + '-' + + String(dateObj.getDate()).padStart(2, '0') + if(field.with_time === true){ + currentDate += 'T' + String(dateObj.getHours()).padStart(2, '0') + ':' + + String(dateObj.getMinutes()).padStart(2, '0'); + } + pendingData[field.id] = currentDate + } + }) + this.dataForm = new Form(pendingData) return } }