Skip to content
Snippets Groups Projects
Unverified Commit fe41c91d authored by Eileen McNaughton's avatar Eileen McNaughton Committed by GitHub
Browse files

Merge pull request #19339 from kainuk/dev_core_2288_sensible

#2288 - Alternative fix search range for select/radio custom fields - now disabling the combination
parents b775bf71 d5fefa0c
Branches
Tags
No related merge requests found
......@@ -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');
}
......
......@@ -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;
}
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment