From 9e30cf03cf4100930cef6d85714ff1457cd6eae5 Mon Sep 17 00:00:00 2001 From: jesscall <34260251+jesscall@users.noreply.github.com> Date: Thu, 29 Aug 2019 10:55:11 -0400 Subject: [PATCH] [candidate_parameter] Consent Status data validation bugfix (#5000) This fixes the logic for data validation on consent status tab. As it stands, if no status stays no or record existed as NULL the validation checks that : - consent date is not empty - withdrawal date is empty However, if Consent Status at one point changes from 'YES' to 'NO' ==> user must fill in date of withdrawal. Therefore, consents that = 'NO' and have non-empty dates of withdrawal are considered non-valid (Displays error message). --- modules/candidate_parameters/ajax/formHandler.php | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/modules/candidate_parameters/ajax/formHandler.php b/modules/candidate_parameters/ajax/formHandler.php index facfa774924..e90b516fc69 100644 --- a/modules/candidate_parameters/ajax/formHandler.php +++ b/modules/candidate_parameters/ajax/formHandler.php @@ -450,9 +450,10 @@ function editConsentStatusFields($db, $user) ]; // Validate data - $recordExists = array_key_exists($consentID, $candidateConsent); - $oldStatus = $candidateConsent[$consentID]['Status'] ?? null; - $validated = false; + $recordExists = array_key_exists($consentID, $candidateConsent); + $oldStatus = $candidateConsent[$consentID]['Status'] ?? null; + $oldWithdrawal = $candidateConsent[$consentID]['DateWithdrawn'] ?? null; + $validated = false; switch ($status) { case 'yes': @@ -477,10 +478,11 @@ function editConsentStatusFields($db, $user) requires only the date of consent.'); return; } - } else { // If no status stays no or record existed as NULL, - // consent date and empty withdrawal date still required + } else { // If no status stays no or record existed as NULL + // consent date required and withdrawal date unchanged if (($oldStatus === null || $oldStatus === 'no') && !empty($date) - && empty($withdrawal) + && ((empty($oldWithdrawal) && empty($withdrawal)) + || (!empty($oldWithdrawal) && !empty($withdrawal))) ) { $validated = true; } else if ($oldStatus === 'yes' && !empty($date)