diff --git a/apps/map/templates/map/form.html b/apps/map/templates/map/form.html index 10cfd4d..ad655c9 100644 --- a/apps/map/templates/map/form.html +++ b/apps/map/templates/map/form.html @@ -56,6 +56,8 @@
+ + {% crispy form %} {% endblock %} @@ -479,26 +481,31 @@ function showDraftPrompt(formSaver, serialisedForm) { } function initDrafts() { - var formSaver = new FormSaver({ + const formSaver = new FormSaver({ formId: 'case-study-form', except: [ 'csrfmiddlewaretoken' ] }) + // Use whether the form has errors as a proxy for whether the server has + // returned us data in the form. In this case, don't show a draft. + const formHasErrors = document.getElementById('form_errors').value === 'true' ? true : false + if (!formHasErrors) { // Get the previous draft, if any - apiGetDraft() - .then(response => response.json()) - .then(json => { - // Handle the case where we didn't get a response - if (!json) return + apiGetDraft() + .then(response => response.json()) + .then(json => { + // Handle the case where we didn't get a response + if (!json) return - if (json.version !== 1) { - throw new Error("Bad JSON response version") - } + if (json.version !== 1) { + throw new Error("Bad JSON response version") + } - showDraftPrompt(formSaver, json.data.form) - }).catch(err => { - console.error(err); - }) + showDraftPrompt(formSaver, json.data.form) + }).catch(err => { + console.error(err); + }) + } // Init the button controller var button = new SaveButton(document.querySelector('.savebutton'))