CRM_Core_Page_AJAX::autocompleteResults($results);
}
- /**
- * Function to fetch the values
- */
- static function autocomplete() {
- $fieldID = CRM_Utils_Type::escape($_GET['cfid'], 'Integer');
- $optionGroupID = CRM_Utils_Type::escape($_GET['ogid'], 'Integer');
- $label = CRM_Utils_Type::escape($_GET['s'], 'String');
-
- $selectOption = CRM_Core_BAO_CustomOption::valuesByID($fieldID, $optionGroupID);
- $results = array();
- foreach ($selectOption as $id => $value) {
- if (strtolower($label) == strtolower(substr($value, 0, strlen($label)))) {
- $results[$id] = $value;
- }
- }
- CRM_Core_Page_AJAX::autocompleteResults($results);
- }
-
static function relationship() {
$relType = CRM_Utils_Array::value('rel_type', $_REQUEST);
$relContactID = CRM_Utils_Array::value('rel_contact', $_REQUEST);
*
* @param int $fieldID the custom field ID
*
- * @return object $field the field object
+ * @return CRM_Core_DAO_CustomField $field the field object
* @static
* public
*/
/**
* This function for building custom fields
*
- * @param object $qf form object (reference)
+ * @param CRM_Core_Form $qf form object (reference)
* @param string $elementName name of the custom field
* @param boolean $inactiveNeeded
* @param boolean $userRequired true if required else false
if ($field->html_type == 'TextArea' && $search) {
$field->html_type = 'Text';
}
+
+ $placeholder = $search ? ts('- any -') : ($useRequired ? ts('- select -') : ts('- none -'));
// FIXME: Why are select state/country separate widget types?
if (in_array($field->html_type, array('Select', 'Multi-Select', 'Select State/Province', 'Multi-Select State/Province', 'Select Country', 'Multi-Select Country'))) {
$field->option_group_id
);
$qf->add('select', $elementName, $label,
- array(
- '' => ts('- select -')) + $selectOption,
+ array('' => $placeholder) + $selectOption,
$useRequired && !$search,
$selectAttributes
);
case 'Select State/Province':
//Add State
- $stateOption = array('' => ts('- select -')) + CRM_Core_PseudoConstant::stateProvince();
+ $stateOption = array('' => $placeholder) + CRM_Core_PseudoConstant::stateProvince();
$qf->add('select', $elementName, $label, $stateOption,
$useRequired && !$search,
$selectAttributes
case 'Select Country':
//Add Country
- $countryOption = array('' => ts('- select -')) + CRM_Core_PseudoConstant::country();
+ $countryOption = array('' => $placeholder) + CRM_Core_PseudoConstant::country();
$qf->add('select', $elementName, $label, $countryOption,
$useRequired && !$search,
$selectAttributes
break;
case 'Autocomplete-Select':
- $qf->add('text', $elementName, $label, $field->attributes,
- $useRequired && !$search
- );
-
- $hiddenEleName = $elementName . '_id';
- if (substr($elementName, -1) == ']') {
- $hiddenEleName = substr($elementName, 0, -1) . '_id]';
- }
- $qf->addElement('hidden', $hiddenEleName, '', array('id' => str_replace(array(']', '['), array('', '_'), $hiddenEleName)));
-
static $customUrls = array();
if ($field->data_type == 'ContactReference') {
+ $qf->add('text', $elementName, $label, $field->attributes,
+ $useRequired && !$search
+ );
+
+ $hiddenEleName = $elementName . '_id';
+ if (substr($elementName, -1) == ']') {
+ $hiddenEleName = substr($elementName, 0, -1) . '_id]';
+ }
+ $qf->addElement('hidden', $hiddenEleName, '', array('id' => str_replace(array(']', '['), array('', '_'), $hiddenEleName)));
+
//$urlParams = "className=CRM_Contact_Page_AJAX&fnName=getContactList&json=1&reset=1&context=customfield&id={$field->id}";
$urlParams = "context=customfield&id={$field->id}";
$qf->addRule($elementName, ts('Select a valid contact for %1.', array(1 => $label)), 'validContact', $actualElementValue);
}
else {
- $customUrls[$elementName] = CRM_Utils_System::url('civicrm/ajax/auto',
- "reset=1&ogid={$field->option_group_id}&cfid={$field->id}",
- FALSE, NULL, FALSE
- );
- $qf->addRule($elementName, ts('Select a valid value for %1.', array(1 => $label)),
- 'autocomplete', array(
- 'fieldID' => $field->id,
- 'optionGroupID' => $field->option_group_id,
- )
+ $attributes = array();
+ // Fixme: why is this a string in the first place???
+ if ($field->attributes) {
+ foreach(explode(' ', $field->attributes) as $at) {
+ if (strpos($at, '=')) {
+ list($k, $v) = explode('=', $at);
+ $attributes[$k] = trim($v, ' "');
+ }
+ }
+ }
+ $attributes += array(
+ 'entity' => 'option_value',
+ 'placeholder' => $placeholder,
+ 'api' => array(
+ 'params' => array('option_group_id' => $field->option_group_id),
+ ),
);
+ $qf->addEntityRef($elementName, $label, $attributes, $useRequired && !$search);
}
$qf->assign('customUrls', $customUrls);
}
}
else {
- $label = CRM_Core_BAO_CustomOption::getOptionLabel($customField->id, $value);
- $defaults[$elementName . '_id'] = $value;
- $defaults[$elementName] = $label;
+ $defaults[$elementName] = $value;
}
break;
}
}
else {
- $label = CRM_Core_BAO_CustomOption::getOptionLabel($field['id'], $value);
- $defaults[$hiddenEleName] = $value;
- $defaults[$elementName] = $label;
+ $defaults[$elementName] = $value;
}
break;
);
}
else {
- if ($field['html_type'] == 'Autocomplete-Select') {
- $wildcard = FALSE;
- $val = array_search($value, $this->_options[$field['id']]);
- }
- elseif (in_array($field['html_type'], array(
- 'Select', 'Radio'))) {
+ if (in_array($field['html_type'], array('Select', 'Radio', 'Autocomplete-Select'))) {
$wildcard = FALSE;
$val = CRM_Utils_Type::escape($value, 'String');
}
$cfID,
$options
);
- if ($htmlType == 'Autocomplete-Select') {
+ if ($field['data_type'] == 'ContactReference') {
$params[$index] = $values[$index];
}
if (CRM_Core_DAO::getFieldValue('CRM_Core_DAO_CustomField',
}
}
else {
- $label = CRM_Core_BAO_CustomOption::getOptionLabel($customFieldId, $details[$name]);
- $defaults[$fldName . '_id'] = $details[$name];
- $defaults[$fldName] = $label;
+ $defaults[$fldName] = $details[$name];
}
break;
<page_callback>CRM_Contact_Page_AJAX::getContactPhone</page_callback>
<access_callback>1</access_callback>
</item>
-<item>
- <path>civicrm/ajax/auto</path>
- <page_callback>CRM_Contact_Page_AJAX::autocomplete</page_callback>
- <access_callback>1</access_callback>
-</item>
<item>
<path>civicrm/ajax/subtype</path>
<page_callback>CRM_Contact_Page_AJAX::buildSubTypes</page_callback>
{if $field.html_type eq 'Autocomplete-Select'}
{if $field.data_type eq 'ContactReference'}
{include file="CRM/Custom/Form/ContactReference.tpl" element_name = $n}
- {else}
- {include file="CRM/Custom/Form/AutoComplete.tpl" element_name = $n}
{/if}
{/if}
{* Show explanatory text for field if not in 'view' or 'preview' modes *}
{else}
{$form.field.$voterId.$fieldName.html}
{/if}
- {if $field.html_type eq 'Autocomplete-Select'}
- {include file="CRM/Custom/Form/AutoComplete.tpl" element_name = field[`$voterId`][`$fieldName`]}
- {/if}
</td>
{/foreach}
{/if}
{assign var="element_name" value="address[$blockId][$element_name]" }
{if $element.data_type eq 'ContactReference'}
{include file="CRM/Custom/Form/ContactReference.tpl"}
- {else}
- {include file="CRM/Custom/Form/AutoComplete.tpl"}
{/if}
{/if}
</td>
{if $fieldName eq 'organization_name'}
<div id="id-onbehalf-orgname-help" class="description">{ts}Start typing the name of an organization that you have saved previously to use it again. Otherwise click "Enter a new organization" above.{/ts}</div>
{/if}
- {if !empty($onBehalfOfFields.$fieldName.html_type) && $onBehalfOfFields.$fieldName.html_type eq 'Autocomplete-Select'}
- {assign var=elementName value=onbehalf[$fieldName]}
- {include file="CRM/Custom/Form/AutoComplete.tpl" element_name=$elementName}
- {/if}
{if $onBehalfOfFields.$fieldName.name|substr:0:5 eq 'phone'}
{assign var="phone_ext_field" value=$onBehalfOfFields.$fieldName.name|replace:'phone':'phone_ext'}
{if $form.onbehalf.$phone_ext_field.html}
+++ /dev/null
-{*
- +--------------------------------------------------------------------+
- | CiviCRM version 4.4 |
- +--------------------------------------------------------------------+
- | Copyright CiviCRM LLC (c) 2004-2013 |
- +--------------------------------------------------------------------+
- | This file is a part of CiviCRM. |
- | |
- | CiviCRM is free software; you can copy, modify, and distribute it |
- | under the terms of the GNU Affero General Public License |
- | Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
- | |
- | CiviCRM is distributed in the hope that it will be useful, but |
- | WITHOUT ANY WARRANTY; without even the implied warranty of |
- | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
- | See the GNU Affero General Public License for more details. |
- | |
- | You should have received a copy of the GNU Affero General Public |
- | License and the CiviCRM Licensing Exception along |
- | with this program; if not, contact CiviCRM LLC |
- | at info[AT]civicrm[DOT]org. If you have questions about the |
- | GNU Affero General Public License or the licensing of CiviCRM, |
- | see the CiviCRM license FAQ at http://civicrm.org/licensing |
- +--------------------------------------------------------------------+
-*}
-{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}";
-
- var customObj = cj(custom);
- var customIdObj = cj(custom_id);
-
- if ( !customObj.hasClass('ac_input') ) {
- customObj.autocomplete( url,
- { width : 250, selectFirst : false, matchContains: true, max: {/literal}{crmSetting name="search_autocomplete_count" group="Search Preferences"}{literal}
- }).result(
- function(event, data ) {
- customIdObj.val( data[1] );
- }
- );
- customObj.click( function( ) {
- customIdObj.val('');
- });
- }
-});
-</script>
-{/literal}
{elseif $element.html_type eq 'Autocomplete-Select'}
{if $element.data_type eq 'ContactReference'}
{include file="CRM/Custom/Form/ContactReference.tpl"}
- {else}
- {include file="CRM/Custom/Form/AutoComplete.tpl"}
{/if}
{/if}
</td>
{if $element.html_type eq 'Autocomplete-Select'}
{if $element.data_type eq 'ContactReference'}
{include file="CRM/Custom/Form/ContactReference.tpl"}
- {else}
- {include file="CRM/Custom/Form/AutoComplete.tpl"}
{/if}
{/if}
</td>
{if $element.html_type eq 'Autocomplete-Select'}
{if $element.data_type eq 'ContactReference'}
{include file="CRM/Custom/Form/ContactReference.tpl"}
- {else}
- {include file="CRM/Custom/Form/AutoComplete.tpl"}
{/if}
{/if}
</td>
{if $field.html_type eq 'Autocomplete-Select'}
{if $field.data_type eq 'ContactReference'}
{include file="CRM/Custom/Form/ContactReference.tpl" element_name = $n}
- {else}
- {include file="CRM/Custom/Form/AutoComplete.tpl" element_name = $n}
{/if}
{/if}
{/if}
{if $field.html_type eq 'Autocomplete-Select'}
{if $field.data_type eq 'ContactReference'}
{include file="CRM/Custom/Form/ContactReference.tpl" element_name = $n}
- {else}
- {include file="CRM/Custom/Form/AutoComplete.tpl" element_name = $n}
{/if}
{/if}
</td>
{if $field.html_type eq 'Autocomplete-Select'}
{if $field.data_type eq 'ContactReference'}
{include file="CRM/Custom/Form/ContactReference.tpl" element_name = $n}
- {else}
- {include file="CRM/Custom/Form/AutoComplete.tpl" element_name = $n}
{/if}
{/if}
</div>
{if $field.html_type eq 'Autocomplete-Select'}
{if $field.data_type eq 'ContactReference'}
{include file="CRM/Custom/Form/ContactReference.tpl" element_name = $n}
- {else}
- {include file="CRM/Custom/Form/AutoComplete.tpl" element_name = $n}
{/if}
{/if}
{/if}