Don't display draft restore prompt after a failed submit attempt (#52)
This commit is contained in:
parent
ee88a3160e
commit
4390edde03
@ -56,6 +56,8 @@
|
||||
|
||||
<div class="savebutton"></div>
|
||||
|
||||
<input type="hidden" id="form_errors" value="{% if form.errors %}true{% else %}false{% endif %}">
|
||||
|
||||
{% 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'))
|
||||
|
Loading…
Reference in New Issue
Block a user