From e71fb06fe9fd2c9011569508532112be4ab653a6 Mon Sep 17 00:00:00 2001 From: Klaas Eikelboom Date: Thu, 7 Jan 2021 11:17:11 +0100 Subject: [PATCH] dev/core#2288 - Alternative fix search range for select/radio custom fields - now disabling the combination --- CRM/Core/BAO/CustomField.php | 37 ++++++++++------------- CRM/Custom/Form/Field.php | 2 +- templates/CRM/Case/Form/Search/Common.tpl | 2 +- 3 files changed, 18 insertions(+), 23 deletions(-) diff --git a/CRM/Core/BAO/CustomField.php b/CRM/Core/BAO/CustomField.php index fd0ee4ffba..601ffd0bb7 100644 --- a/CRM/Core/BAO/CustomField.php +++ b/CRM/Core/BAO/CustomField.php @@ -812,27 +812,22 @@ class CRM_Core_BAO_CustomField extends CRM_Core_DAO_CustomField { // For all select elements case 'Select': $fieldAttributes['class'] = ltrim(($fieldAttributes['class'] ?? '') . ' crm-select2'); - if ($field->is_search_range && $search && in_array($field->data_type, $rangeDataTypes)) { - $qf->add('text', $elementName . '_from', $label . ' ' . ts('From'), $fieldAttributes); - $qf->add('text', $elementName . '_to', ts('To'), $fieldAttributes); + + if (empty($fieldAttributes['multiple'])) { + $options = ['' => $placeholder] + $options; } - else { - if (empty($fieldAttributes['multiple'])) { - $options = ['' => $placeholder] + $options; - } - $element = $qf->add('select', $elementName, $label, $options, $useRequired && !$search, $fieldAttributes); - - // Add and/or option for fields that store multiple values - if ($search && self::isSerialized($field)) { - $qf->addRadio($elementName . '_operator', '', [ - 'or' => ts('Any'), - 'and' => ts('All'), - ], [], NULL, FALSE, [ - 'or' => ['title' => ts('Results may contain any of the selected options')], - 'and' => ['title' => ts('Results must have all of the selected options')], - ]); - $qf->setDefaults([$elementName . '_operator' => 'or']); - } + $element = $qf->add('select', $elementName, $label, $options, $useRequired && !$search, $fieldAttributes); + + // Add and/or option for fields that store multiple values + if ($search && self::isSerialized($field)) { + $qf->addRadio($elementName . '_operator', '', [ + 'or' => ts('Any'), + 'and' => ts('All'), + ], [], NULL, FALSE, [ + 'or' => ['title' => ts('Results may contain any of the selected options')], + 'and' => ['title' => ts('Results must have all of the selected options')], + ]); + $qf->setDefaults([$elementName . '_operator' => 'or']); } break; @@ -929,7 +924,7 @@ class CRM_Core_BAO_CustomField extends CRM_Core_DAO_CustomField { switch ($field->data_type) { case 'Int': // integers will have numeric rule applied to them. - if ($field->is_search_range && $search) { + if ($field->is_search_range && $search && $widget != 'Select') { $qf->addRule($elementName . '_from', ts('%1 From must be an integer (whole number).', [1 => $label]), 'integer'); $qf->addRule($elementName . '_to', ts('%1 To must be an integer (whole number).', [1 => $label]), 'integer'); } diff --git a/CRM/Custom/Form/Field.php b/CRM/Custom/Form/Field.php index 39a38af5a0..32a845ed7f 100644 --- a/CRM/Custom/Form/Field.php +++ b/CRM/Custom/Form/Field.php @@ -836,7 +836,7 @@ AND option_group_id = %2"; //fix for 'is_search_range' field. if (in_array($params['data_type'], ['Int', 'Float', 'Money', 'Date'])) { - if (empty($params['is_searchable'])) { + if (empty($params['is_searchable']) || in_array($params['html_type'], ['Radio', 'Select'])) { $params['is_search_range'] = 0; } } diff --git a/templates/CRM/Case/Form/Search/Common.tpl b/templates/CRM/Case/Form/Search/Common.tpl index a6eb66cbc0..7916fa018c 100644 --- a/templates/CRM/Case/Form/Search/Common.tpl +++ b/templates/CRM/Case/Form/Search/Common.tpl @@ -58,8 +58,8 @@ {include file="CRM/common/Tagset.tpl" tagsetType='case'} - {if $caseGroupTree} + Keboom {include file="CRM/Custom/Form/Search.tpl" groupTree=$caseGroupTree showHideLinks=false} -- 2.25.1