$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
);
{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},