From 9f38846687530de331c31aa3397820334991026e Mon Sep 17 00:00:00 2001 From: Coleman Watts Date: Tue, 5 Aug 2014 17:21:32 +0100 Subject: [PATCH] CRM-15061 - Add multivalue support for autocomplete fields --- CRM/Core/BAO/CustomField.php | 1 + CRM/Core/BAO/CustomQuery.php | 17 +++++++++-------- 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/CRM/Core/BAO/CustomField.php b/CRM/Core/BAO/CustomField.php index 102ac39085..d96ddfbf67 100644 --- a/CRM/Core/BAO/CustomField.php +++ b/CRM/Core/BAO/CustomField.php @@ -996,6 +996,7 @@ class CRM_Core_BAO_CustomField extends CRM_Core_DAO_CustomField { $attributes += array( 'entity' => 'option_value', 'placeholder' => $placeholder, + 'multiple' => $search, 'api' => array( 'params' => array('option_group_id' => $field->option_group_id), ), diff --git a/CRM/Core/BAO/CustomQuery.php b/CRM/Core/BAO/CustomQuery.php index 9d6e64a561..8ca162022e 100644 --- a/CRM/Core/BAO/CustomQuery.php +++ b/CRM/Core/BAO/CustomQuery.php @@ -351,6 +351,11 @@ SELECT label, value $fieldName = "{$field['table_name']}.{$field['column_name']}"; + // Autocomplete comes back as a string not an array + if ($field['data_type'] == 'String' && $field['html_type'] == 'Autocomplete-Select' && $op == '=') { + $value = explode(',', $value); + } + // Handle multi-select search for any data type if (is_array($value) && !$field['is_search_range']) { $isSerialized = CRM_Core_BAO_CustomField::isSerialized($field); @@ -379,7 +384,9 @@ SELECT label, value } // fix $value here to escape sql injection attacks - $value = CRM_Core_DAO::escapeString(trim($value)); + if (!is_array($value)) { + $value = CRM_Core_DAO::escapeString(trim($value)); + } $qillValue = CRM_Core_BAO_CustomField::getDisplayValue($value, $id, $this->_options); @@ -397,13 +404,7 @@ SELECT label, value ); } else { - if (in_array($field['html_type'], array('Select', 'Radio', 'Autocomplete-Select'))) { - $wildcard = FALSE; - $val = CRM_Utils_Type::escape($value, 'String'); - } - else { - $val = CRM_Utils_Type::escape($strtolower(trim($value)), 'String'); - } + $val = CRM_Utils_Type::escape($strtolower(trim($value)), 'String'); if ($wildcard) { $val = $strtolower(CRM_Core_DAO::escapeString($val)); -- 2.25.1