Skip to content

Commit

Permalink
VACMS-17426: Requires VA facility location when the event is using a …
Browse files Browse the repository at this point in the history
…VA facility location type (#17859)

* VACMS-17426: Requires VA facility location when the event is using a VA facility location type.

* VACMS-17426: Conditionally sets the requirement for Event Location Type.
  • Loading branch information
dsasser committed Apr 27, 2024
1 parent 88f21dd commit b8ec013
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 0 deletions.
15 changes: 15 additions & 0 deletions docroot/modules/custom/va_gov_events/js/eventFormHelpers.es6.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,9 @@
const fieldFacilityLocation = document.getElementById(
"edit-field-facility-location-0-target-id"
);
const fieldFacilityLocationLabel = document.querySelector(
"label[for='edit-field-facility-location-0-target-id']"
);
const fieldLocationTypeOnline = document.getElementById(
"edit-field-location-type-online"
);
Expand Down Expand Up @@ -292,11 +295,22 @@
}
};

const toggleFacilityLocationRequiredFields = (enableDisable, addRemove) => {
// Facility location field.
if (fieldFacilityLocation) {
fieldFacilityLocation.required = enableDisable;
}
if (fieldFacilityLocationLabel) {
fieldFacilityLocationLabel.classList[addRemove]("form-required");
}
};

const toggleLocationElements = () => {
targetLocationElements.forEach((element) => {
element.style.display = "none";
});
toggleAddressRequiredFields(false, "remove");
toggleFacilityLocationRequiredFields(false, "remove");
if (fieldLocationTypeFacility.checked) {
fieldFacilityLocationWrapper.style.display = "block";
fieldLocationHumanreadableWrapper.style.display = "block";
Expand All @@ -305,6 +319,7 @@
fieldAddressLine2.value = "";
fieldAddressLocality.value = "";
fieldAddressAdminArea.value = "";
toggleFacilityLocationRequiredFields(true, "add");
}
if (fieldLocationTypeNonFacility.checked) {
fieldLocationHumanreadableWrapper.style.display = "block";
Expand Down
11 changes: 11 additions & 0 deletions docroot/modules/custom/va_gov_events/js/eventFormHelpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
var targetLocationElements = document.querySelectorAll("#edit-field-facility-location-wrapper, #edit-field-url-of-an-online-event-wrapper, #edit-field-location-humanreadable-wrapper, #edit-field-address-wrapper");
var fieldFacilityLocationWrapper = document.getElementById("edit-field-facility-location-wrapper");
var fieldFacilityLocation = document.getElementById("edit-field-facility-location-0-target-id");
var fieldFacilityLocationLabel = document.querySelector("label[for='edit-field-facility-location-0-target-id']");
var fieldLocationTypeOnline = document.getElementById("edit-field-location-type-online");
var fieldAddressWrapper = document.getElementById("edit-field-address-wrapper");
var fieldUrlOfOnlineEvent = document.getElementById("edit-field-url-of-an-online-event-0-uri");
Expand Down Expand Up @@ -135,11 +136,20 @@
fieldAddressAdminAreaLabel.classList[addRemove]("form-required");
}
};
var toggleFacilityLocationRequiredFields = function toggleFacilityLocationRequiredFields(enableDisable, addRemove) {
if (fieldFacilityLocation) {
fieldFacilityLocation.required = enableDisable;
}
if (fieldFacilityLocationLabel) {
fieldFacilityLocationLabel.classList[addRemove]("form-required");
}
};
var toggleLocationElements = function toggleLocationElements() {
targetLocationElements.forEach(function (element) {
element.style.display = "none";
});
toggleAddressRequiredFields(false, "remove");
toggleFacilityLocationRequiredFields(false, "remove");
if (fieldLocationTypeFacility.checked) {
fieldFacilityLocationWrapper.style.display = "block";
fieldLocationHumanreadableWrapper.style.display = "block";
Expand All @@ -148,6 +158,7 @@
fieldAddressLine2.value = "";
fieldAddressLocality.value = "";
fieldAddressAdminArea.value = "";
toggleFacilityLocationRequiredFields(true, "add");
}
if (fieldLocationTypeNonFacility.checked) {
fieldLocationHumanreadableWrapper.style.display = "block";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ Feature: Content Type: Event
And I fill in autocomplete field with selector "#edit-field-url-of-an-online-event-0-uri" with value "https://va.gov"
And I select the "At a VA facility" radio button
Then an element with the selector "#edit-field-facility-location-0-target-id" should be empty
And the element with selector "#edit-field-facility-location-0-target-id" should have attribute "required"
When I select the "At a non-VA location" radio button
Then an element with the selector "#edit-field-address-0-address-address-line1" should be empty
And an element with the selector "#edit-field-address-0-address-locality" should be empty
Expand Down

0 comments on commit b8ec013

Please sign in to comment.