Skip to content

Commit

Permalink
[#188] Make "Time Period" field required, but un-require "from" and "…
Browse files Browse the repository at this point in the history
…to" fields for relative date selections
  • Loading branch information
jensschuppe committed Dec 13, 2023
1 parent acb7fa9 commit 9585ce2
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 2 deletions.
16 changes: 15 additions & 1 deletion CRM/Donrec/Form/Task/ContributeTask.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ function buildQuickForm() {
'donrec_contribution_horizon',
E::ts('Time period'),
FALSE,
FALSE,
TRUE,
E::ts('From:'),
E::ts('To:'),
[],
Expand Down Expand Up @@ -71,6 +71,20 @@ function setDefaultValues() {
}
}

/**
* {@inheritDoc}
*/
public function validate() {
// Do not require "from" and "to" fields for time period with relative date
// selected. Custom time period has value "0".
$selectedPeriod = $this->getElement('donrec_contribution_horizon_relative')->getValue();
if (reset($selectedPeriod) !== "0") {
unset($this->_required[array_search('donrec_contribution_horizon_from', $this->_required)]);
unset($this->_required[array_search('donrec_contribution_horizon_to', $this->_required)]);
}
return parent::validate();
}

function postProcess() {
// CAUTION: changes to this function should also be done in CRM_Donrec_Form_Task_Create:postProcess()

Expand Down
16 changes: 15 additions & 1 deletion CRM/Donrec/Form/Task/DonrecTask.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ function buildQuickForm() {
'donrec_contribution_horizon',
E::ts('Time Period'),
FALSE,
FALSE,
TRUE,
E::ts('From:'),
E::ts('To:'),
[],
Expand Down Expand Up @@ -71,6 +71,20 @@ function setDefaultValues() {
}
}

/**
* {@inheritDoc}
*/
public function validate() {
// Do not require "from" and "to" fields for time period with relative date
// selected. Custom time period has value "0".
$selectedPeriod = $this->getElement('donrec_contribution_horizon_relative')->getValue();
if (reset($selectedPeriod) !== "0") {
unset($this->_required[array_search('donrec_contribution_horizon_from', $this->_required)]);
unset($this->_required[array_search('donrec_contribution_horizon_to', $this->_required)]);
}
return parent::validate();
}

function postProcess() {
// CAUTION: changes to this function should also be done in CRM_Donrec_Form_Task_Create:postProcess()

Expand Down

0 comments on commit 9585ce2

Please sign in to comment.