From 9585ce247545f34d82d2e78f302722938312329e Mon Sep 17 00:00:00 2001 From: Jens Schuppe Date: Wed, 13 Dec 2023 15:21:26 +0100 Subject: [PATCH] [#188] Make "Time Period" field required, but un-require "from" and "to" fields for relative date selections --- CRM/Donrec/Form/Task/ContributeTask.php | 16 +++++++++++++++- CRM/Donrec/Form/Task/DonrecTask.php | 16 +++++++++++++++- 2 files changed, 30 insertions(+), 2 deletions(-) diff --git a/CRM/Donrec/Form/Task/ContributeTask.php b/CRM/Donrec/Form/Task/ContributeTask.php index 57d9166..2b6eb13 100644 --- a/CRM/Donrec/Form/Task/ContributeTask.php +++ b/CRM/Donrec/Form/Task/ContributeTask.php @@ -34,7 +34,7 @@ function buildQuickForm() { 'donrec_contribution_horizon', E::ts('Time period'), FALSE, - FALSE, + TRUE, E::ts('From:'), E::ts('To:'), [], @@ -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() diff --git a/CRM/Donrec/Form/Task/DonrecTask.php b/CRM/Donrec/Form/Task/DonrecTask.php index 44b3b7f..b9a6fb6 100644 --- a/CRM/Donrec/Form/Task/DonrecTask.php +++ b/CRM/Donrec/Form/Task/DonrecTask.php @@ -34,7 +34,7 @@ function buildQuickForm() { 'donrec_contribution_horizon', E::ts('Time Period'), FALSE, - FALSE, + TRUE, E::ts('From:'), E::ts('To:'), [], @@ -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()