From 6df8788c1958241f182ddf89534c0d2981ad0ded Mon Sep 17 00:00:00 2001 From: Alexandre Date: Mon, 2 Nov 2020 13:36:59 +0100 Subject: [PATCH] =?UTF-8?q?feat:=20sauvegarder=20le=20profil=20dans=20le?= =?UTF-8?q?=20localstorage=20pour=20pr=C3=A9-remplir=20le=20formulaire?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/js/form-util.js | 2 ++ src/js/form.js | 9 +++++++++ 2 files changed, 11 insertions(+) diff --git a/src/js/form-util.js b/src/js/form-util.js index 9e50f166..05035607 100644 --- a/src/js/form-util.js +++ b/src/js/form-util.js @@ -128,6 +128,8 @@ export function prepareInputs (formInputs, reasonInputs, reasonFieldset, reasonA } console.log(getProfile(formInputs), reasons) + + window.localStorage.setItem('savedProfile', JSON.stringify(getProfile(formInputs))) const pdfBlob = await generatePdf(getProfile(formInputs), reasons, pdfBase) diff --git a/src/js/form.js b/src/js/form.js index 1965a8c0..c3f03c1b 100644 --- a/src/js/form.js +++ b/src/js/form.js @@ -29,6 +29,7 @@ const createFormGroup = ({ minlength, name, pattern, + value, placeholder = '', type = 'text', }) => { @@ -53,6 +54,7 @@ const createFormGroup = ({ maxlength, name, pattern, + value, placeholder, required: true, type, @@ -141,6 +143,12 @@ export function createForm () { } const appendToForm = appendTo(form) + + let savedProfile = null + try { + savedProfile = JSON.parse(window.localStorage.getItem('savedProfile')) + } catch (e) { + } const formFirstPart = formData .flat(1) @@ -152,6 +160,7 @@ export function createForm () { autofocus: index === 0, ...field, name: field.key, + value: savedProfile && savedProfile[field.key] ? savedProfile[field.key] : '', }) return formGroup