Fixed set default for date fields

This commit is contained in:
CiviWare Solutions 2019-03-31 04:43:01 +05:30
parent c9aa4e0955
commit d975405623

View File

@ -82,13 +82,16 @@ class CRM_EntityTemplates_Utils {
if ($form->_entityTemplateId) {
$formValues = CRM_EntityTemplates_BAO_EntityTemplates::getFormValues($form->_entityTemplateId);
$formValues['entity_template_id'] = $form->_entityTemplateId;
self::formatDateParams($formValues, $form->_elements);
$form->setDefaults($formValues);
CRM_Core_Resources::singleton()->addScript("
CRM.$(function($) {
$(document).ajaxSend(function(event, jqxhr, settings) {
if (settings.url .indexOf('civicrm/custom') != -1) {
settings.url = settings.url + '&templateId={$form->_entityTemplateId}';
}
}
});
})",
10,
@ -143,4 +146,24 @@ class CRM_EntityTemplates_Utils {
}
}
/**
* Format Date field values in params.
*
* @param array $params
* @param object $elements
*/
public static function formatDateParams(&$params, $elements) {
foreach ($elements as $element) {
if (!empty($element->_attributes) && array_key_exists(
'data-crm-datepicker',
$element->_attributes
)) {
$name = $element->_attributes['name'];
if (!CRM_Utils_System::isNull($params[$name])) {
$params[$name] = date('Y-m-d H:i:s', strtotime($params[$name]));
}
}
}
}
}