Skip to content
Snippets Groups Projects
Unverified Commit a410253b authored by Eileen McNaughton's avatar Eileen McNaughton Committed by GitHub
Browse files

Merge pull request #17804 from seamuslee001/date

#1847 Fix datepicker to respect the searchDate offsets
parents 6ea4f106 4c69df35
No related branches found
No related tags found
No related merge requests found
......@@ -359,6 +359,8 @@ class CRM_Core_Form extends HTML_QuickForm_Page {
*
* @return HTML_QuickForm_Element
* Could be an error object
*
* @throws \CRM_Core_Exception
*/
public function &add(
$type, $name, $label = '',
......@@ -385,16 +387,34 @@ class CRM_Core_Form extends HTML_QuickForm_Page {
unset($attributes['multiple']);
$extra = NULL;
}
// @see http://wiki.civicrm.org/confluence/display/CRMDOC/crmDatepicker
if ($type == 'datepicker') {
$attributes = ($attributes ? $attributes : []);
// @see https://docs.civicrm.org/dev/en/latest/framework/ui/#date-picker
if ($type === 'datepicker') {
$attributes = $attributes ?: [];
if (!empty($attributes['format'])) {
$dateAttributes = CRM_Core_SelectValues::date($attributes['format'], NULL, NULL, NULL, 'Input');
if (empty($extra['minDate']) && !empty($dateAttributes['minYear'])) {
$extra['minDate'] = $dateAttributes['minYear'] . '-01-01';
}
if (empty($extra['maxDate']) && !empty($dateAttributes['minYear'])) {
$extra['maxDate'] = $dateAttributes['maxYear'] . '-12-31';
}
}
// Support minDate/maxDate properties
if (isset($extra['minDate'])) {
$extra['minDate'] = date('Y-m-d', strtotime($extra['minDate']));
}
if (isset($extra['maxDate'])) {
$extra['maxDate'] = date('Y-m-d', strtotime($extra['maxDate']));
}
$attributes['data-crm-datepicker'] = json_encode((array) $extra);
if (!empty($attributes['aria-label']) || $label) {
$attributes['aria-label'] = CRM_Utils_Array::value('aria-label', $attributes, $label);
}
$type = "text";
}
if ($type == 'select' && is_array($extra)) {
if ($type === 'select' && is_array($extra)) {
// Normalize this property
if (!empty($extra['multiple'])) {
$extra['multiple'] = 'multiple';
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment