diff --git a/softcreditcustomfields.php b/softcreditcustomfields.php index 342ac5e..517ac82 100644 --- a/softcreditcustomfields.php +++ b/softcreditcustomfields.php @@ -188,7 +188,18 @@ function softcreditcustomfields_civicrm_buildForm($formName, &$form) { ); _softcreditcustomfields_addCustomDataToForm($form, $entityId, $blockId); } - + if ($form->_flagSubmitted) { + $submitValues = $form->_submitValues; + foreach ($form->_required as $key => $fieldName) { + if (strpos($fieldName, 'soft_credit_custom[') !== FALSE) { + $fieldName = str_replace('soft_credit_custom[', '', $fieldName); + $blockId = strstr($fieldName, ']', TRUE); + if (empty($submitValues['soft_credit_amount'][$blockId])) { + unset($form->_required[$key]); + } + } + } + } } } /** @@ -234,10 +245,6 @@ function _softcreditcustomfields_addCustomDataToForm(&$form, $entityId, $blockId // And we can't set it to 'soft_credit_' because we want to set it in a slightly different format. CRM_Core_BAO_CustomGroup::buildQuickForm($form, $groupTree, FALSE, 'dnc_'); - // during contact editing : if no softCredit is filled - // required custom data must not produce 'required' form rule error - // more handling done in formRule func - //self::storeRequiredCustomDataInfo($form, $groupTree); $tplGroupTree = CRM_Core_Smarty::singleton() ->get_template_vars('soft_credit_custom_groupTree'); $tplGroupTree = empty($tplGroupTree) ? [] : $tplGroupTree;