),
)
);
- $participantFee = &$form->add('text', 'participant_fee_level', ts('Fee Level'));
-
- //elements for assigning value operation
- $participantFeeId = &$form->add('hidden', 'participant_fee_id', '', array('id' => 'participant_fee_id'));
+ $form->add('text', 'participant_fee_id', ts('Fee Level'), array('class' => 'big crm-ajax-select'));
CRM_Core_Form_Date::buildDateRange($form, 'event', 1, '_start_date_low', '_end_date_high', ts('From'), FALSE);
/**
* Function for building EventFee combo box
+ * FIXME: This ajax callback could be eliminated in favor of an entityRef field but the priceFieldValue api doesn't currently support filtering on entity_table
*/
function eventFee() {
- $name = trim(CRM_Utils_Type::escape($_GET['s'], 'String'));
+ $name = trim(CRM_Utils_Type::escape($_GET['term'], 'String'));
if (!$name) {
$name = '%';
$dao = CRM_Core_DAO::executeQuery($query);
$results = array();
while ($dao->fetch()) {
- $results[$dao->id] = $dao->label;
+ $results[] = array('id' => $dao->id, 'text' => $dao->label);
}
- CRM_Core_Page_AJAX::autocompleteResults($results);
+ echo json_encode($results);
+ CRM_Utils_System::civiExit();
}
}
</td>
</tr>
<tr>
- <td class="crm-event-form-block-participant_fee_level">
- {$form.participant_fee_level.label}<br />{$form.participant_fee_level.html}
+ <td class="crm-event-form-block-participant_fee_id">
+ {$form.participant_fee_id.label}<br />{$form.participant_fee_id.html}
</td>
<td class="crm-event-form-block-participant_fee_amount">
<label>{ts}Fee Amount{/ts}</label><br />
{literal}
<script type="text/javascript">
-var feeUrl = "{/literal}{$dataURLEventFee}{literal}";
-
-cj('#participant_fee_level').autocomplete( feeUrl, { width : 180, selectFirst : false, matchContains: true
-}).result(function(event, data, formatted) { cj( "input#participant_fee_id" ).val( data[1] );
- }).bind( 'click', function( ) { cj( "input#participant_fee_id" ).val(''); });
+cj(function($) {
+ // FIXME: This could be much simpler as an entityRef field but the priceFieldValue api doesn't currently support the filters we need
+ $('#participant_fee_id').select2({
+ placeholder: {/literal}'{ts escape="js"}- any -{/ts}'{literal},
+ minimumInputLength: 1,
+ allowClear: true,
+ ajax: {
+ url: "{/literal}{$dataURLEventFee}{literal}",
+ data: function(term) {
+ return {term: term};
+ },
+ results: function(response) {
+ return {results: response};
+ }
+ },
+ initSelection: function(el, callback) {
+ CRM.api3('price_field_value', 'getsingle', {id: $(el).val()}).done(function(data) {
+ callback({id: data.id, text: data.label});
+ });
+ }
+ });
+});
</script>
{/literal}