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; flex-grow: 1;
} }
.errors {
color: #a40f0f;
}
#body { #body {
flex-grow: 1; flex-grow: 1;
} }

View File

@ -20,7 +20,11 @@
} }
return ""; return "";
} }
function loadCookies() { function init() {
{% if errors %}
window.scrollTo(0, document.body.scrollHeight);
{% endif %}
if (document.getElementById('company').value === "BananaCorp") { if (document.getElementById('company').value === "BananaCorp") {
return return
} }
@ -43,7 +47,7 @@
} }
} }
} }
window.onload = loadCookies; window.onload = init;
</script> </script>
</head> </head>
<body> <body>
@ -61,14 +65,26 @@
{{ render_field(form.body, 'class=bigtext') }} {{ render_field(form.body, 'class=bigtext') }}
{{ render_field(form.closingtext) }} {{ render_field(form.closingtext) }}
</dl> </dl>
{% if err %} {% if errors %}
<p> <div id=errors>
{% for error in err %} <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> {{ error }}<br>
{% endfor %} {% endfor %}
</p> </p>
</div>
{% endif %} {% 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> </form>
</body> </body>

View File

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