title: How To Attach Knockout Validation To A Custom Binding
body: <p>I have created a Knockout custom binding to format dates using moment.js.</p>
  
  <pre><code>ko.bindingHandlers.dateStringValue = {
      update: function (element, valueAccessor, allBindingsAccessor, viewModel) {
          var value = valueAccessor(),
          allBindings = allBindingsAccessor();
          var valueUnwrapped = ko.utils.unwrapObservable(value);
  
          if (valueUnwrapped === null) {
              ko.bindingHandlers.value.update(element, valueAccessor, allBindingsAccessor, viewModel);
              $(element).val("");
          } else {
              ko.bindingHandlers.value.update(element, valueAccessor, allBindingsAccessor, viewModel);
              var pattern = allBindings.datePattern || "MM/DD/YYYY";
              $(element).val(moment(valueUnwrapped).format(pattern));
          }
      }
  };
  </code></pre>
  
  <p>This works great with my binding:</p>
  
  <pre><code>&lt;input type="text" data-bind="dateStringValue: entryDate, datePattern: 'M/D/YYYY'" /&gt;
  </code></pre>
  
  <p>I created a custom validation rule from code I found on the web.</p>
  
  <pre><code>// http://stackoverflow.com/a/23086828/139917
  // Use: var someDate= ko.observable().extend({ simpleDate: true });
  // Dependencies: date.js
  ko.validation.rules['simpleDate'] = {
      validator: function (val, validate) {
          var d = Date.parse(val);
          return (d != null);
          //return ko.validation.utils.isEmptyVal(val) || moment(val, 'MM/DD/YYYY').isValid();
      },
      message: 'Invalid date entry date'
  };
  
  ko.validation.registerExtenders();
  </code></pre>
  
  <p>I tried both moment.js and date.js date libraries.</p>
  
  <p>I attached the custom validation rule to my viewmodel observable.</p>
  
  <p><code>self.entryDate = ko.observable(je.entryDate || new Date()).extend({ simpleDate: true });</code></p>
  
  <p>Now I want to use Knockout Validation to validate input but don't know how to let the validation framework know about my new binding. It seems Knockout Validation only knows about some or all of the built in Knockout bindings.</p>
  
  <p>Calling <code>ko.validation.makeBindingHandlerValidatable("dateStringValue");</code> raises a <code>0x800a138f - JavaScript runtime error: Object expected</code> error in Knockout v3.2.0. It has been suggested that calling into the Knockout value binding from my custom binding would work but code like <code>ko.bindingHandlers.value.update(element, valueAccessor);</code> have not worked for me.</p>
  
  <p>How can I let Knockout Validation know about my custom binding?</p>