From: Coleman Watts Date: Mon, 21 Dec 2015 12:10:54 +0000 (-0500) Subject: CRM-16019 - Fix crmDatepicker format handling X-Git-Url: https://vcs.fsf.org/?a=commitdiff_plain;h=a29737219c307acb5a530944f2b9623654eea74f;p=civicrm-core.git CRM-16019 - Fix crmDatepicker format handling --- diff --git a/CRM/Core/Form.php b/CRM/Core/Form.php index c387db99a6..96393a5a8c 100644 --- a/CRM/Core/Form.php +++ b/CRM/Core/Form.php @@ -331,8 +331,9 @@ class CRM_Core_Form extends HTML_QuickForm_Page { $attributes['class'] .= ' crm-form-wysiwyg'; $type = "textarea"; } + // @see http://wiki.civicrm.org/confluence/display/CRMDOC/crmDatepicker if ($type == 'datepicker') { - $attributes = ($attributes ? $attributes : array()) + array('class' => ''); + $attributes = ($attributes ? $attributes : array()); $attributes['data-crm-datepicker'] = json_encode((array) $extra); $type = "text"; } diff --git a/js/Common.js b/js/Common.js index 2dbf522b22..27a8a74030 100644 --- a/js/Common.js +++ b/js/Common.js @@ -600,7 +600,7 @@ if (!CRM.vars) CRM.vars = {}; function copyAttributes($source, $target, attributes) { _.each(attributes, function(name) { - if ($source.attr(name)) { + if ($source.attr(name) !== undefined) { $target.attr(name, $source.attr(name)); } }); @@ -642,17 +642,22 @@ if (!CRM.vars) CRM.vars = {}; $dateField = $('').insertAfter($dataField); copyAttributes($dataField, $dateField, ['placeholder', 'style', 'class', 'disabled']); $dateField.addClass('crm-form-text crm-form-date'); - settings.date = typeof settings.date === 'string' ? settings.date : CRM.config.dateInputFormat; - settings.changeMonth = _.includes(settings.date, 'm'); - settings.changeYear = _.includes(settings.date, 'y'); + settings.dateFormat = typeof settings.date === 'string' ? settings.date : CRM.config.dateInputFormat; + settings.changeMonth = _.includes(settings.dateFormat, 'm'); + settings.changeYear = _.includes(settings.dateFormat, 'y'); settings.minDate = settings.minDate ? CRM.utils.makeDate(settings.minDate) : null; settings.maxDate = settings.maxDate ? CRM.utils.makeDate(settings.maxDate) : null; $dateField.datepicker(settings).change(updateDataField); } // Rudimentary validation. TODO: Roll into use of jQUery validate and ui.datepicker.validation function isValidDate() { + // FIXME: parseDate doesn't work with incomplete date formats; skip validation if no month, day or year in format + var lowerFormat = settings.dateFormat.toLowerCase(); + if (lowerFormat.indexOf('y') < 0 || lowerFormat.indexOf('m') < 0 || lowerFormat.indexOf('d') < 0) { + return true; + } try { - $.datepicker.parseDate(settings.date, $dateField.val()); + $.datepicker.parseDate(settings.dateFormat, $dateField.val()); return true; } catch (e) { return false;