CRM-16019 - Fix crmDatepicker format handling
authorColeman Watts <coleman@civicrm.org>
Mon, 21 Dec 2015 12:10:54 +0000 (07:10 -0500)
committerColeman Watts <coleman@civicrm.org>
Tue, 22 Dec 2015 03:30:56 +0000 (22:30 -0500)
CRM/Core/Form.php
js/Common.js

index c387db99a67f18d8951d48a8b3174666c2e98085..96393a5a8c47c1af2ad07d458dd6bc7538d0df07 100644 (file)
@@ -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";
     }
index 2dbf522b22906527c718617b9cd8611043e0a2c0..27a8a740308268f385548ac7dd8df9c5d184b47e 100644 (file)
@@ -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 = $('<input>').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;