{*
+--------------------------------------------------------------------+
- | CiviCRM version 4.3 |
+ | CiviCRM version 4.5 |
+--------------------------------------------------------------------+
- | Copyright CiviCRM LLC (c) 2004-2013 |
+ | Copyright CiviCRM LLC (c) 2004-2014 |
+--------------------------------------------------------------------+
| This file is a part of CiviCRM. |
| |
| see the CiviCRM license FAQ at http://civicrm.org/licensing |
+--------------------------------------------------------------------+
*}
+{* Js needed to initialize custom field of type ContactReference *}
{literal}
<script type="text/javascript">
-cj( function( ) {
- var url = "{/literal}{$customUrls.$element_name}{literal}";
- var custom = "{/literal}#{$element_name|replace:']':''|replace:'[':'_'}{literal}";
- var custom_id = "{/literal}input[name=\"{$element_name|cat:'_id'|regex_replace:'/\]_id$/':'_id]'}\"]{literal}";
+ CRM.$(function($) {
+ var $field = $("{/literal}#{$element_name|replace:']':''|replace:'[':'_'}{literal}");
- var customObj = cj(custom);
- var customIdObj = cj(custom_id);
-
- if ( !customObj.hasClass('ac_input') ) {
- customObj.autocomplete( url,
- { width : 250, selectFirst : false, elementId: custom, matchContains: true, formatResult: {/literal}validate{$element_name|replace:']':''|replace:'[':'_'|replace:'-':'_'}{literal}
- }).result(
- function(event, data) {
- cj(custom_id).val(data[1]);
- }
- );
- customObj.click( function( ) {
- customIdObj.val('');
- });
- }
+ $field.crmSelect2({
+ placeholder: {/literal}'{ts escape="js"}- select contact -{/ts}'{literal},
+ minimumInputLength: 1,
+ ajax: {
+ url: {/literal}"{$customUrls.$element_name}"{literal},
+ data: function(term) {
+ return {term: term};
+ },
+ results: function(response) {
+ return {results: response};
+ }
+ },
+ initSelection: function($el, callback) {
+ callback($el.data('entity-value'));
+ }
+ });
});
-
-function validate{/literal}{$element_name|replace:']':''|replace:'[':'_'|replace:'-':'_'}{literal}( Data, position ) {
- if ( Data[1] == 'error' ) {
- cj(this.elementId).parent().append("<span id='"+ (this.elementId).substr(1) +"_error' class='hiddenElement messages crm-error'>" + "{/literal}{ts escape='js'}Invalid parameters for contact search.{/ts}{literal}" + "</span>");
- cj(this.elementId + '_error').fadeIn(800).fadeOut(5000, function( ){ cj(this).remove(); });
- Data[1] = '';
- }
-}
</script>
{/literal}