From 70b558fa0fd18dfa4488f895611eb0c606c8bd2c Mon Sep 17 00:00:00 2001 From: CamilleBeau Date: Wed, 3 Nov 2021 16:11:57 -0400 Subject: [PATCH] [candidate_parameters] Allow clearing of consent status --- .../candidate_parameters/ajax/formHandler.php | 8 +++++ .../candidate_parameters/jsx/ConsentStatus.js | 29 ++++++++++++------- 2 files changed, 26 insertions(+), 11 deletions(-) diff --git a/modules/candidate_parameters/ajax/formHandler.php b/modules/candidate_parameters/ajax/formHandler.php index 8a8db53c7ee..3bb3e861ea3 100644 --- a/modules/candidate_parameters/ajax/formHandler.php +++ b/modules/candidate_parameters/ajax/formHandler.php @@ -450,6 +450,7 @@ function editConsentStatusFields(\Database $db) // Validate data $recordExists = array_key_exists($consentID, $candidateConsent); $oldStatus = $candidateConsent[$consentID]['Status'] ?? null; + $oldDate = $candidateConsent[$consentID]['DateGiven'] ?? null; $oldWithdrawal = $candidateConsent[$consentID]['DateWithdrawn'] ?? null; $validated = false; @@ -505,7 +506,14 @@ function editConsentStatusFields(\Database $db) echo('A status is missing for at least one consent type. Please select a valid status for all consent types.'); return; + } elseif (!empty($oldStatus) + || !empty($oldDate) + || !empty($oldWithdrawal) + ) { + // Only update empty fields if they were not already empty + $validated = true; } + break; } diff --git a/modules/candidate_parameters/jsx/ConsentStatus.js b/modules/candidate_parameters/jsx/ConsentStatus.js index 59a7d44aa9c..d026d3972f7 100644 --- a/modules/candidate_parameters/jsx/ConsentStatus.js +++ b/modules/candidate_parameters/jsx/ConsentStatus.js @@ -99,11 +99,21 @@ class ConsentStatus extends Component { if (this.state.Data.consents.hasOwnProperty(consent)) { const oldConsent = this.state.Data.consentStatuses[consent]; const newConsent = this.state.formData[consent]; - // Clear withdrawal date if consent status changes from no - // (or empty if uncleaned data) to yes if (formElement === consent) { + // Clear withdrawal date if consent status changes from no + // (or empty if uncleaned data) to yes if ((newConsent === 'yes' && oldConsent !== 'yes') || - (newConsent === 'no' && oldConsent === null)) { + (newConsent === 'no' && + (oldConsent === null || oldConsent === '') + ) + ) { + formData[consent + '_withdrawal'] = ''; + formData[consent + '_withdrawal2'] = ''; + } + // Clear date if response set back to null + if (newConsent === '' && oldConsent !== null) { + formData[consent + '_date'] = ''; + formData[consent + '_date2'] = ''; formData[consent + '_withdrawal'] = ''; formData[consent + '_withdrawal2'] = ''; } @@ -300,18 +310,20 @@ class ConsentStatus extends Component { const newConsent = this.state.formData[consentName]; const withdrawalDate = this.state.Data.withdrawals[consentName]; // Define defaults - let emptyOption = true; let dateRequired = false; + let responseDateDisabled = true; let withdrawalRequired = false; // Let date of withdrawal field be disabled until it is needed let withdrawalDisabled = true; // If answer to consent is 'yes', require date of consent if (newConsent === 'yes') { + responseDateDisabled = false; dateRequired = true; } // If answer to consent is 'no', require date of consent if (newConsent === 'no') { + responseDateDisabled = false; dateRequired = true; // If answer was previously 'yes' and consent is now being withdrawn, enable and require withdrawal date // If consent was previously withdrawn and stays withdrawn, enable and require withdrawal date @@ -322,10 +334,6 @@ class ConsentStatus extends Component { withdrawalRequired = true; } } - // Disallow clearing a valid consent status by removing empty option - if (oldConsent === 'no' || oldConsent === 'yes') { - emptyOption = false; - } // Set up elements const label = this.state.Data.consents[consentName]; @@ -353,14 +361,13 @@ class ConsentStatus extends Component { onUserInput={this.setFormData} disabled={disabled} required={false} - emptyOption={emptyOption} />