Skip to content

Commit

Permalink
dev/core#1847 Fix datepicker to respect the searchDate offsets
Browse files Browse the repository at this point in the history
I have some misgivings about this since I suspect the rationale behind the search offsets was primarily about the clunky UI.

Having said that I think the datepicker UI is a bit clunky on this front too as it's not obvious you can choose earlier
dates. This does at least restore established behaviour.

https://lab.civicrm.org/dev/core/-/issues/1847
  • Loading branch information
eileenmcnaughton committed Jul 13, 2020
1 parent 3d3b6a3 commit 8a35c7e
Showing 1 changed file with 15 additions and 3 deletions.
18 changes: 15 additions & 3 deletions CRM/Core/Form.php
Original file line number Diff line number Diff line change
Expand Up @@ -359,6 +359,8 @@ public function registerRules() {
*
* @return HTML_QuickForm_Element
* Could be an error object
*
* @throws \CRM_Core_Exception
*/
public function &add(
$type, $name, $label = '',
Expand All @@ -385,8 +387,19 @@ public function &add(
unset($attributes['multiple']);
$extra = NULL;
}

// @see https://docs.civicrm.org/dev/en/latest/framework/ui/#date-picker
if ($type == 'datepicker') {
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']));
Expand All @@ -395,14 +408,13 @@ public function &add(
$extra['maxDate'] = date('Y-m-d', strtotime($extra['maxDate']));
}

$attributes = ($attributes ? $attributes : []);
$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';
Expand Down

0 comments on commit 8a35c7e

Please sign in to comment.