From: Coleman Watts Date: Fri, 27 May 2016 01:43:42 +0000 (-0400) Subject: CRM-18660 - Fix custom field year range selection X-Git-Url: https://vcs.fsf.org/?a=commitdiff_plain;h=8d6beca6ec0041edbe7877e370c1898a0afb2e02;p=civicrm-core.git CRM-18660 - Fix custom field year range selection This fixes the yearRange setting to be the responsibility of the crmDatepicker widget instead of setting it from php. The php implementation was also buggy. --- diff --git a/CRM/Core/BAO/CustomField.php b/CRM/Core/BAO/CustomField.php index ec67256b03..6036e61cd9 100644 --- a/CRM/Core/BAO/CustomField.php +++ b/CRM/Core/BAO/CustomField.php @@ -908,7 +908,6 @@ class CRM_Core_BAO_CustomField extends CRM_Core_DAO_CustomField { //CRM-18487 - max date should be the last date of the year. 'maxDate' => isset($maxYear) ? $maxYear . '-12-31' : NULL, 'time' => $field->time_format ? $field->time_format * 12 : FALSE, - 'yearRange' => "{$minYear}:{$maxYear}", ); if ($field->is_search_range && $search) { $qf->add('datepicker', $elementName . '_from', $label, $attr + array('placeholder' => ts('From')), FALSE, $params); diff --git a/js/Common.js b/js/Common.js index d9ec1d7a1d..f3aae29500 100644 --- a/js/Common.js +++ b/js/Common.js @@ -655,12 +655,15 @@ if (!CRM.vars) CRM.vars = {}; $dateField = $('').insertAfter($dataField); copyAttributes($dataField, $dateField, ['placeholder', 'style', 'class', 'disabled']); $dateField.addClass('crm-form-' + type); - settings.minDate = settings.minDate ? CRM.utils.makeDate(settings.minDate) : null; - settings.maxDate = settings.maxDate ? CRM.utils.makeDate(settings.maxDate) : null; if (hasDatepicker) { + settings.minDate = settings.minDate ? CRM.utils.makeDate(settings.minDate) : null; + settings.maxDate = settings.maxDate ? CRM.utils.makeDate(settings.maxDate) : null; settings.dateFormat = typeof settings.date === 'string' ? settings.date : CRM.config.dateInputFormat; settings.changeMonth = _.includes(settings.dateFormat, 'm'); settings.changeYear = _.includes(settings.dateFormat, 'y'); + if (!settings.yearRange && settings.minDate !== null && settings.maxDate !== null) { + settings.yearRange = '' + CRM.utils.formatDate(settings.minDate, 'yy') + ':' + CRM.utils.formatDate(settings.maxDate, 'yy'); + } $dateField.addClass('crm-form-date').datepicker(settings); } else { $dateField.attr('min', settings.minDate ? CRM.utils.formatDate(settings.minDate, 'yy') : '1000');