title: Validate 1 field  (unobtrusive) when other field changes, and check only 1 rule
body: <p>Is there any way to trigger a <em>specific</em> jquery-unobtrusive rule on one field, when the value in another field changes?</p>
  
  <p>I have a form with two date fields (say start/end) on it, with validation that <code>end</code> must be greater than <code>start</code>.  This works fine in the simple case of changing <code>end</code> after <code>start</code> is already set.  What it doesn't do is allow for is:</p>
  
  <ul>
  <li>setting <code>end</code> first and then setting <code>start</code></li>
  <li>changing <code>start</code> after both have already been set, and violating the constraint</li>
  </ul>
  
  <p>Server side validation will catch it of course, but it looks bad to have the error on <code>end</code> stay set even after you have fixed <code>start</code>, or no error showing up when the value in <code>end</code> is changed to an invalid value.  The reason to trigger a specific rule is that I don't want to fire off the <code>required</code> or <code>date</code> format rules on the same field before the user has had a chance to enter a value.  The form starts off 'clean'.  However, if that isn't possible then firing all the rules is ok.</p>
  
  <p>Sorry for no code samples, but I don't even know where to start with this.</p>
  
  <p><em><strong>Update:</em></strong></p>
  
  <p>What i've done for the moment is to dig around in the model (since this is an asp.net mvc project), find the attribute, and read it's properties directly.</p>
  
  <pre><code>var controllerCtx = ViewContext.Controller.ControllerContext;
  var da = ViewData.ModelMetadata.GetValidators(controllerCtx)
              .SelectMany(x =&gt; x.GetClientValidationRules())
              .Where(x =&gt; x.ValidationType == "isdateafter")
              .FirstOrDefault();
  
  var otherid = da == null ? "" : da.ValidationParameters["propertytested"];
  </code></pre>
  
  <p>Then in the normal HTML part, I do a test on the <code>start</code> and see if it is a date picker, then wire up a basic check, and fire off all validation rules.  Since there aren't many rules, I just check to see if there is a value in the <code>end</code> field before running them.  I'd like to use the ingenious solution below, and will give it a go when I have a bit of free time this week.</p>
  
  <pre><code>@if (otherid != "") {
      &lt;text&gt;
      var other = $("#@otherid");
      if (other &amp;&amp; other.hasClass('hasDatepicker')) { // if the other box is a date/time picker
         other.datetimepicker('option', 'onSelect', function(dateText, instance) {
             var lowerTime = $(this).datetimepicker('getDate');
             $("#@id").datetimepicker('option', 'minDate', new Date(lowerTime.getTime()));
             if ($("#@id").val()) { // if there is a value in the other
                  $('form').data('validator').element('#@id');
             }
          });
      }
      &lt;/text&gt;
  }
  </code></pre>