Color and notate errors. Clear them on submit

This commit is contained in:
Sage Vaillancourt 2021-07-28 18:43:19 -04:00
parent 8892135160
commit 4a32e0206f
3 changed files with 31 additions and 11 deletions

View File

@ -97,6 +97,10 @@ textarea {
flex-grow: 1;
}
.errors {
color: #a40f0f;
}
#body {
flex-grow: 1;
}

View File

@ -20,7 +20,11 @@
}
return "";
}
function loadCookies() {
function init() {
{% if errors %}
window.scrollTo(0, document.body.scrollHeight);
{% endif %}
if (document.getElementById('company').value === "BananaCorp") {
return
}
@ -43,7 +47,7 @@
}
}
}
window.onload = loadCookies;
window.onload = init;
</script>
</head>
<body>
@ -61,14 +65,26 @@
{{ render_field(form.body, 'class=bigtext') }}
{{ render_field(form.closingtext) }}
</dl>
{% if err %}
<p>
{% for error in err %}
{% if errors %}
<div id=errors>
<h3>Your letter has errors.</h3>
<p>There is likely a typo in one of your variables (the {\blabla} bits).
<br>Make sure each is spelled correctly, and has the correct brackets on either
side</p>
<p class=errors>
{% for error in errors %}
{{ error }}<br>
{% endfor %}
</p>
</div>
{% endif %}
<p><input type=submit value="Submit"></p>
<p><input type=submit value="Submit"
{% if errors %}
onclick="var elem = document.getElementById('errors'); elem.parentNode.removeChild(elem);"
{% endif %}
></p>
</form>
</body>

View File

@ -61,12 +61,12 @@ def index():
body=form.body.data,
)
(resp, err) = data.generate_pdf()
(resp, errors) = data.generate_pdf()
# Save entered data as cookies on user's machine
if err:
if errors:
resp = make_response(render_template('writing.html',
form=form,
err=err,
errors=errors,
))
for pair in data.get_pairs():
resp.set_cookie(pair[0], urllib.parse.quote(pair[1]))