dev/core#362 fixing contact reference fields on On Behalf Profiles search and select...
authorAlice Frumin <alice@aghstrategies.com>
Thu, 6 Sep 2018 18:08:45 +0000 (14:08 -0400)
committerAlice Frumin <alice@aghstrategies.com>
Thu, 27 Sep 2018 19:17:38 +0000 (15:17 -0400)
CRM/Core/BAO/CustomField.php
templates/CRM/Custom/Form/ContactReference.tpl

index 6fc3fe7d49e7b014b058d60f7e2da1a98afe97e7..ba33cb9fec605732d7fd673204416d700723739d 100644 (file)
@@ -1062,8 +1062,12 @@ class CRM_Core_BAO_CustomField extends CRM_Core_DAO_CustomField {
           $element = $qf->add('text', $elementName, $label, $attributes, $useRequired && !$search);
 
           $urlParams = "context=customfield&id={$field->id}";
-
-          $customUrls[$elementName] = CRM_Utils_System::url('civicrm/ajax/contactref',
+          $idOfelement = $elementName;
+          // dev/core#362 if in an onbehalf profile clean up the name to get rid of square brackets that break the select 2 js
+          if (strpos($elementName, '[') && strpos($elementName, ']')) {
+            $idOfelement = substr(substr($elementName, (strpos($elementName, '[') + 1)), 0, -1);
+          }
+          $customUrls[$idOfelement] = CRM_Utils_System::url('civicrm/ajax/contactref',
             $urlParams,
             FALSE, NULL, FALSE
           );
index ab464693eb9449e5a316781e012f2bdbf4df3fda..a5eb9a3b8cc67abe6322a1e1bd628c4f3bacc006 100644 (file)
@@ -28,7 +28,8 @@
 {literal}
 <script type="text/javascript">
   CRM.$(function($) {
-    var $field = $("{/literal}#{$element_name|replace:']':''|replace:'[':'_'}{literal}");
+    // dev/core#362 if in an onbehalf profile reformat the id
+    var $field = $("{/literal}#{if $prefix}{$prefix}_{/if}{$element_name|replace:']':''|replace:'[':'_'}{literal}");
 
     $field.crmSelect2({
       placeholder: {/literal}'{ts escape="js"}- select contact -{/ts}'{literal},