Skip to content

Commit

Permalink
Merge pull request #571 from CityOfNewYork/johnyu95-fix-custom-forms-…
Browse files Browse the repository at this point in the history
…loading

Fix Custom Forms Loading Part 2
  • Loading branch information
johnyu95 authored Nov 20, 2023
2 parents 8d8cd25 + 4a2f3fe commit 3b107a0
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 1 deletion.
11 changes: 10 additions & 1 deletion app/request/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -141,8 +141,17 @@ def new():
)

custom_metadata = json.loads(
flask_request.form.get("custom-request-forms-data", {})
flask_request.form.get("custom-request-forms-data", '{}')
)
# validate that custom_metadata JSON has data if custom request forms are enabled for the agency
agency_ein = (form.request_agency.data
if form.request_agency.data != "None"
else current_user.default_agency_ein)
agency_object = Agencies.query.filter_by(ein=agency_ein).first()
if agency_object.agency_features["custom_request_forms"]["enabled"] and not custom_metadata:
flash('An unexpected error occurred. Please reload the page and try submitting your request again.',
category='danger')
return redirect(url_for("request.new"))
# validate that form_name exists in custom_metadata JSON
for key,value in custom_metadata.items():
form_name = value.get('form_name', None)
Expand Down
10 changes: 10 additions & 0 deletions app/static/js/request/new-request-agency.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,16 @@
"use strict";

$(document).ready(function () {
// Reload the page if it was loaded from a cached version (back browser button).
// Used to clear out form data and ensure custom request forms are properly loaded.
(function () {
window.onpageshow = function (event) {
if (event.persisted) {
window.location.reload();
}
};
})();

// Determine if the agencyRequestInstructions and custom request forms need to be shown on page load.
getRequestAgencyInstructions();
// Check for custom request forms on page load (browser back button behavior).
Expand Down
10 changes: 10 additions & 0 deletions app/static/js/request/new-request-user.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,16 @@
"use strict";

$(document).ready(function () {
// Reload the page if it was loaded from a cached version (back browser button).
// Used to clear out form data and ensure custom request forms are properly loaded.
(function () {
window.onpageshow = function (event) {
if (event.persisted) {
window.location.reload();
}
};
})();

// Determine if the agencyRequestInstructions need to be shown on page load.
getRequestAgencyInstructions();
// Check for custom request forms on page load (browser back button behavior).
Expand Down
11 changes: 11 additions & 0 deletions app/templates/request/new_request_anon.js.html
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,16 @@
"use strict";

$(document).ready(function () {
// Reload the page if it was loaded from a cached version (back browser button).
// Used to clear out form data and ensure custom request forms are properly loaded.
(function () {
window.onpageshow = function (event) {
if (event.persisted) {
window.location.reload();
}
};
})();

{% if kiosk_mode %}
$("#request-category").prop('disabled', true);
$("#request-agency").prop('disabled', true);
Expand All @@ -24,6 +34,7 @@
{% if title %}
$("#request-title").val("{{ title }}");
{% endif %}

// Determine if the agencyRequestInstructions need to be shown on page load.
getRequestAgencyInstructions();
// Check for custom request forms on page load (browser back button behavior).
Expand Down

0 comments on commit 3b107a0

Please sign in to comment.