Skip to content

Commit

Permalink
[candidate_parameters] Allow clearing of consent status
Browse files Browse the repository at this point in the history
  • Loading branch information
CamilleBeau committed Nov 30, 2022
1 parent ad0460c commit 70b558f
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 11 deletions.
8 changes: 8 additions & 0 deletions modules/candidate_parameters/ajax/formHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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;
}

Expand Down
29 changes: 18 additions & 11 deletions modules/candidate_parameters/jsx/ConsentStatus.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'] = '';
}
Expand Down Expand Up @@ -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
Expand All @@ -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];
Expand Down Expand Up @@ -353,22 +361,21 @@ class ConsentStatus extends Component {
onUserInput={this.setFormData}
disabled={disabled}
required={false}
emptyOption={emptyOption}
/>
<DateElement
label={consentDateLabel}
name={consentDate}
value={this.state.formData[consentDate]}
onUserInput={this.setFormData}
disabled={disabled}
disabled={disabled || responseDateDisabled}
required={dateRequired}
/>
<DateElement
label={consentDateConfirmationLabel}
name={consentDate2}
value={this.state.formData[consentDate2]}
onUserInput={this.setFormData}
disabled={disabled}
disabled={disabled || responseDateDisabled}
required={dateRequired}
/>
<DateElement
Expand Down

0 comments on commit 70b558f

Please # to comment.