title: Comparing two fields with knockout-validation
body: <p>I have a viewmodel for a form that I'm trying to add validation to using knockout-validation.  </p>
  
  <pre><code>fromDate: ko.observable(
              moment().subtract('days', 1).startOf('day').format(dateFormat)
            ),
  toDate: ko.observable(
              moment().startOf('day').format(dateFormat)
          ),
  </code></pre>
  
  <p>I need to make sure that the from date is less than the to date.  I can't seem to get any form of custom validator to pick up the reference to the second observable.  I need something along the lines of:</p>
  
  <pre><code>toDate: ko.observable(moment().startOf('day').format(dateFormat)).extend({
            validation: {
              validator: function (val, someOtherVal) {
                  return moment(val) &gt;= moment(someOtherVal);
              },
              message: 'Must be greater or equal to From Date',
              params: viewModel.fromDate()
            }
          }),
  </code></pre>
  
  <p>Any ideas?</p>
  
  <p><strong>Update</strong></p>
  
  <p>I'm sure I'd already tried this, but moving the extension method into the onload function works.</p>
  
  <pre><code>$(function () {
      ko.validation.configure({ decorateElement: true });
  
      viewModel.toDate.extend({
      validation: {
              validator: function (val, someOtherVal) {
                  return moment(val) &gt;= moment(viewModel.fromDate());
              },
              message: 'To date must be greater than from date',
          }
      });
  
      ko.applyBindings(viewModel);
  });
  </code></pre>