$dao = CRM_Core_DAO::executeQuery($query);
$results = array();
while ($dao->fetch()) {
- $results[$dao->id] = $dao->data;
+ $results[] = array('id' => $dao->id, 'text' => $dao->data);
}
- CRM_Core_Page_AJAX::autocompleteResults($results);
+ print json_encode($results);
+ CRM_Utils_System::civiExit();
}
static function relationship() {
$siteHasPCPs = CRM_Contribute_PseudoConstant::pcPage();
if (!CRM_Utils_Array::crmIsEmptyArray($siteHasPCPs)) {
$form->assign('siteHasPCPs', 1);
- $pcpDataUrl = CRM_Utils_System::url('civicrm/ajax/rest',
- 'className=CRM_Contact_Page_AJAX&fnName=getPCPList&json=1&context=contact&reset=1',
- FALSE, NULL, FALSE
- );
- $form->assign('pcpDataUrl', $pcpDataUrl);
- $form->addElement('text', 'pcp_made_through', ts('Credit to a Personal Campaign Page'));
- $form->addElement('hidden', 'pcp_made_through_id', '', array('id' => 'pcp_made_through_id'));
+ $form->add('hidden', 'pcp_made_through'); // stores the label
+ $form->add('text', 'pcp_made_through_id', ts('Credit to a Personal Campaign Page'), array('class' => 'twenty'));
$form->addElement('checkbox', 'pcp_display_in_roll', ts('Display in Honor Roll?'), NULL);
$form->addElement('text', 'pcp_roll_nickname', ts('Name (for Honor Roll)'));
$form->addElement('textarea', 'pcp_personal_note', ts('Personal Note (for Honor Roll)'));
if (!empty($fields['pcp_display_in_roll']) || !empty($fields['pcp_roll_nickname']) ||
CRM_Utils_Array::value('pcp_personal_note', $fields)
) {
- $errors['pcp_made_through'] = ts('Please select a Personal Campaign Page, OR uncheck Display in Honor Roll and clear both the Honor Roll Name and the Personal Note field.');
+ $errors['pcp_made_through_id'] = ts('Please select a Personal Campaign Page, OR uncheck Display in Honor Roll and clear both the Honor Roll Name and the Personal Note field.');
}
}
</td>
</tr>
<tr class="crm-contribution-pcp-block crm-contribution-form-block-pcp_made_through_id hiddenElement">
- <td class="label">{$form.pcp_made_through.label}</td>
+ <td class="label">{$form.pcp_made_through_id.label}</td>
<td>
- {$form.pcp_made_through.html}
+ {$form.pcp_made_through_id.html}
<span class="showSoftCreditLink">
<a href="#" id="showSoftCredit">{ts}unlink from personal campaign page{/ts}</a>
</span><br/>
return false;
});
- var pcpURL = CRM.url('civicrm/ajax/rest',
- 'className=CRM_Contact_Page_AJAX&fnName=getPCPList&json=1&context=contact&reset=1');
- $('#pcp_made_through').autocomplete(pcpURL,
- { width : 360, selectFirst : false, matchContains: true
- }).result( function(event, data, formatted) {
- $("#pcp_made_through_id" ).val( data[1]);
- });
+ // FIXME: This could be much simpler as an entityRef field but pcp doesn't have a searchable api :(
+ var pcpURL = CRM.url('civicrm/ajax/rest', 'className=CRM_Contact_Page_AJAX&fnName=getPCPList&json=1&context=contact&reset=1');
+ $('#pcp_made_through_id').crmSelect2({
+ placeholder: {/literal}'{ts escape="js"}- select -{/ts}'{literal},
+ minimumInputLength: 1,
+ ajax: {
+ url: pcpURL,
+ data: function(term) {
+ return {term: term};
+ },
+ results: function(response) {
+ return {results: response};
+ }
+ },
+ initSelection: function(el, callback) {
+ callback({id: $(el).val(), text: $('#pcp_made_through').val()});
+ }
+ });
$('.crm-soft-credit-block tr span').each(function () {
if ($(this).hasClass('crm-error')) {