From 8a6cfaa9fc08e246363906fefabf9e5348f02688 Mon Sep 17 00:00:00 2001 From: Coleman Watts Date: Fri, 7 Feb 2014 21:39:18 -0800 Subject: [PATCH] CRM-13966 - CRM-14165 - Add select2 & popup links for custom fields --- CRM/Contact/Form/Edit/Individual.php | 6 +++--- CRM/Core/BAO/CustomField.php | 31 ++++++++++++++++++++++------ css/civicrm.css | 2 +- 3 files changed, 29 insertions(+), 10 deletions(-) diff --git a/CRM/Contact/Form/Edit/Individual.php b/CRM/Contact/Form/Edit/Individual.php index 2ceac12ca2..00c6351e8a 100644 --- a/CRM/Contact/Form/Edit/Individual.php +++ b/CRM/Contact/Form/Edit/Individual.php @@ -44,7 +44,7 @@ class CRM_Contact_Form_Edit_Individual { * This function provides the HTML form elements that are specific * to the Individual Contact Type * - * @param object $form form object + * @param CRM_Core_Form $form form object * @param int $inlineEditMode ( 1 for contact summary * top bar form and 2 for display name edit ) * @@ -63,7 +63,7 @@ class CRM_Contact_Form_Edit_Individual { //prefix $prefix = CRM_Core_PseudoConstant::get('CRM_Contact_DAO_Contact', 'prefix_id'); if (isset($nameFields['Prefix']) && !empty($prefix)) { - $form->addElement('select', 'prefix_id', ts('Prefix'), array('' => '') + $prefix); + $form->addSelect('prefix_id', array('class' => 'four', 'placeholder' => ' ')); } $attributes = CRM_Core_DAO::getAttribute('CRM_Contact_DAO_Contact'); @@ -90,7 +90,7 @@ class CRM_Contact_Form_Edit_Individual { // suffix $suffix = CRM_Core_PseudoConstant::get('CRM_Contact_DAO_Contact', 'suffix_id'); if (isset($nameFields['Suffix']) && $suffix) { - $form->addElement('select', 'suffix_id', ts('Suffix'), array('' => '') + $suffix); + $form->addSelect('suffix_id', array('class' => 'four', 'placeholder' => ' ')); } } diff --git a/CRM/Core/BAO/CustomField.php b/CRM/Core/BAO/CustomField.php index ebcce7d398..aba4f6df3c 100644 --- a/CRM/Core/BAO/CustomField.php +++ b/CRM/Core/BAO/CustomField.php @@ -753,6 +753,25 @@ class CRM_Core_BAO_CustomField extends CRM_Core_DAO_CustomField { $field->html_type = 'Text'; } + // FIXME: Why are select state/country separate widget types? + if (in_array($field->html_type, array('Select', 'Multi-Select', 'Select State/Province', 'Multi-Select State/Province', 'Select Country', 'Multi-Select Country'))) { + $selectAttributes = array( + 'data-crm-custom' => $dataCrmCustomVal, + 'class' => 'crm-select2', + ); + if (strpos($field->html_type, 'Multi') === 0) { + $selectAttributes['multiple'] = 'multiple'; + } + } + // Add popup link for editing options. Normally this is handled by CRM_Core_Form->addSelect + if (in_array($field->html_type, array('Select', 'Multi-Select')) && !$search && CRM_Core_Permission::check('administer CiviCRM')) { + $selectAttributes += array( + 'data-api-entity' => 'contact', // FIXME: This works because the getoptions api isn't picky about custom fields, but it's WRONG + 'data-api-field' => 'custom_' . $field->id, + 'data-option-group-url' => 'civicrm/admin/options/' . CRM_Core_DAO::getFieldValue('CRM_Core_DAO_OptionGroup', $field->option_group_id), + ); + } + if (!isset($label)) { $label = $field->label; } @@ -867,7 +886,7 @@ class CRM_Core_BAO_CustomField extends CRM_Core_DAO_CustomField { array( '' => ts('- select -')) + $selectOption, $useRequired && !$search, - $dataCrmCustomAttr + $selectAttributes ); break; @@ -912,7 +931,7 @@ class CRM_Core_BAO_CustomField extends CRM_Core_DAO_CustomField { ) { $selectOption['CiviCRM_OP_OR'] = ts('Select to match ANY; unselect to match ALL'); } - $qf->addElement('select', $elementName, $label, $selectOption, array('size' => '5', 'multiple', 'data-crm-custom' => $dataCrmCustomVal)); + $qf->addElement('select', $elementName, $label, $selectOption, $selectAttributes); if ($useRequired && !$search) { $qf->addRule($elementName, ts('%1 is a required field.', array(1 => $label)), 'required'); @@ -958,7 +977,7 @@ class CRM_Core_BAO_CustomField extends CRM_Core_DAO_CustomField { $stateOption = array('' => ts('- select -')) + CRM_Core_PseudoConstant::stateProvince(); $qf->add('select', $elementName, $label, $stateOption, $useRequired && !$search, - $dataCrmCustomAttr + $selectAttributes ); $qf->_stateCountryMap['state_province'][] = $elementName; break; @@ -967,7 +986,7 @@ class CRM_Core_BAO_CustomField extends CRM_Core_DAO_CustomField { //Add Multi-select State/Province $stateOption = CRM_Core_PseudoConstant::stateProvince(); - $qf->addElement('select', $elementName, $label, $stateOption, array('size' => '5', 'multiple', 'data-crm-custom' => $dataCrmCustomVal)); + $qf->addElement('select', $elementName, $label, $stateOption, $selectAttributes); if ($useRequired && !$search) { $qf->addRule($elementName, ts('%1 is a required field.', array(1 => $label)), 'required'); } @@ -978,7 +997,7 @@ class CRM_Core_BAO_CustomField extends CRM_Core_DAO_CustomField { $countryOption = array('' => ts('- select -')) + CRM_Core_PseudoConstant::country(); $qf->add('select', $elementName, $label, $countryOption, $useRequired && !$search, - $dataCrmCustomAttr + $selectAttributes ); $qf->_stateCountryMap['country'][] = $elementName; break; @@ -986,7 +1005,7 @@ class CRM_Core_BAO_CustomField extends CRM_Core_DAO_CustomField { case 'Multi-Select Country': //Add Country $countryOption = CRM_Core_PseudoConstant::country(); - $qf->addElement('select', $elementName, $label, $countryOption, array('size' => '5', 'multiple', 'data-crm-custom' => $dataCrmCustomVal)); + $qf->addElement('select', $elementName, $label, $countryOption, $selectAttributes); if ($useRequired && !$search) { $qf->addRule($elementName, ts('%1 is a required field.', array(1 => $label)), 'required'); } diff --git a/css/civicrm.css b/css/civicrm.css index 5421b6a593..71b9c279b9 100644 --- a/css/civicrm.css +++ b/css/civicrm.css @@ -3769,7 +3769,7 @@ div.m ul#civicrm-menu, width: 15em; } .crm-container .select2-container { - min-width: 8em !important; + min-width: 6em !important; font-size: 11px; } /* Style civi form inputs to match select2 */ -- 2.25.1