Commits

Matthew Schinckel  committed 5acb7aa

Handle still sending form using browser.

  • Participants
  • Parent commits 7f2fe5d

Comments (0)

Files changed (1)

File src/js/datepicker.js

         if (acc.call) {
           valueAccessor()(newValue);
         } else {
-          valueAccessor() = newValue;
+          valueAccessor(newValue);
         }
       }
     });
-    var $element = $(element);
-    // TODO read this in automatically from ../html/datepicker.template.html
-    var $widget = $("<div class=\"koui datepicker widget\"><header><button class=\"prev-month\" data-bind=\"click: prevMonth, enable: prevMonth.enabled\"></button><button class=\"next-month\" data-bind=\"click: nextMonth, enable: nextMonth.enabled\"></button><span class=\"month-year-selector\"><select data-bind=\"options:monthChoices, optionsText:'name', optionsValue:'value', value:visibleMonth\"></select><select data-bind=\"options:yearChoices, value:visibleYear\"></select></span></header><ul class=\"messages\" data-bind=\"visible: error\"><li class=\"error\" data-bind=\"text: error\"></li></ul><table><thead><tr><!-- ko if: showWeekNumbers --><th data-bind=\"text: weekNumberTitle\"></th><!-- /ko --><!-- ko foreach: weekdays --><th data-bind=\"text: $data\"></th><!-- /ko --></tr></thead><tbody data-bind=\"foreach: visibleWeeks\"><tr><!-- ko if: $root.showWeekNumbers --><th data-bind=\"text: $data[0].getWeek()\"></th><!-- /ko --><!-- ko foreach: $data --><td data-bind=\"text: getDate(), click: $root.selectDate, css: css\"></td><!-- /ko --></tr></tbody></table><footer><button data-bind=\"click: selectToday, text: strings.today\"></button><button class=\"done\" data-bind=\"click: hide, text: strings.done\"></button></footer></div>");
-    var options = ko.mapping.fromJS(ko.bindingHandlers.date.defaultOptions, {});
-    ko.mapping.fromJS(allBindingsAccessor().dateOptions || {}, options);
-    
     /*
     Take a value, and ensure it is a date.
     */
       }
       return new Date(Date.parse(date));
     };
+
+    var $element = $(element);
+    // TODO: have a nice little button added that triggers the datepicker.
+    // $element.after("<button class='koui-datepicker-trigger'></button>")
+    
+    // If the element has a name attribute, we want to shadow the element in a new hidden element.
+    // This allows for posting to the server.
+    if ($element.attr('name')) {
+      var name = $element.attr('name');
+      var $shadow = $('<input name="' + name + '" type="hidden" data-bind="value: iso_date">');
+      $element.removeAttr('name');
+      $element.after($shadow);
+      var iso_date = ko.computed(function(){
+        return ensureDate(value()).strftime(Date.ISO_DATE);
+      });
+      ko.applyBindings({iso_date: iso_date}, $shadow[0]);
+    }
+    
+    // TODO read this in automatically from ../html/datepicker.template.html
+    var $widget = $("<div class=\"koui datepicker widget\"><header><button class=\"prev-month\" data-bind=\"click: prevMonth, enable: prevMonth.enabled\"></button><button class=\"next-month\" data-bind=\"click: nextMonth, enable: nextMonth.enabled\"></button><span class=\"month-year-selector\"><select data-bind=\"options:monthChoices, optionsText:'name', optionsValue:'value', value:visibleMonth\"></select><select data-bind=\"options:yearChoices, value:visibleYear\"></select></span></header><ul class=\"messages\" data-bind=\"visible: error\"><li class=\"error\" data-bind=\"text: error\"></li></ul><table><thead><tr><!-- ko if: showWeekNumbers --><th data-bind=\"text: weekNumberTitle\"></th><!-- /ko --><!-- ko foreach: weekdays --><th data-bind=\"text: $data\"></th><!-- /ko --></tr></thead><tbody data-bind=\"foreach: visibleWeeks\"><tr><!-- ko if: $root.showWeekNumbers --><th data-bind=\"text: $data[0].getWeek()\"></th><!-- /ko --><!-- ko foreach: $data --><td data-bind=\"text: getDate(), click: $root.selectDate, css: css\"></td><!-- /ko --></tr></tbody></table><footer><button data-bind=\"click: selectToday, text: strings.today\"></button><button class=\"done\" data-bind=\"click: hide, text: strings.done\"></button></footer></div>");
+    var options = ko.mapping.fromJS(ko.bindingHandlers.date.defaultOptions, {});
+    ko.mapping.fromJS(allBindingsAccessor().dateOptions || {}, options);
+    
     
     var setDate = function setDate(newDate) {
       // When we set the date, we don't want to stomp over the time, if it is set.
         return {name:m, value:i};
       })),
       visibleYear: ko.computed({
-        read: function(){ return visibleDate().getFullYear();},
+        read: function(){ 
+          return visibleDate().getFullYear();
+        },
         write: function(newValue) {
           visibleDate(new Date(visibleDate().setFullYear(newValue)));
         }