Commits

Matthew Schinckel committed 3fa45bd

Correctly parse dates in input fields according to defined format.

  • Participants
  • Parent commits baa49e9

Comments (0)

Files changed (1)

File jquery/static/jquery.jqui/js/datepicker.js

   
   Knockout-savvy datepicker.
   
+  This is still a bit all over the show. I think I want to move everything inside
+  the handler definition, but I also want to have the widget generated on the fly.
+  
+  
  */
 
 ko.bindingHandlers.datepicker = {
     element.datepicker = dp;
     
     ko.utils.registerEventHandler(element, "change", function() {
-      value(new Date(Date.parse($(element).val())));
+      value(dp.parseDate($(element).val()));
       dp.hide();
     });
     
   dp.setDate = function setDate(date) {
     selectedDate(new Date(Date.parse(date)));
   };
-    
+  
+  dp.parseDate = function parseDate(dateString) {
+    return new Date(Date.strptime(dateString, options.displayFormat()));
+  };
+  
   dp.updateOptions = function updateOptions(newOptions) {
     ko.mapping.fromJS(newOptions, {}, options);
   };
+  
   return dp;
 };