title: MVC Adding methods into jquery.validate.unobtrusive.js
body: <p>I recently had a question on <a href="https://stackoverflow.com/questions/6923430/mvc-unobtrusive-validation-on-checkbox-not-working/6931490#6931490">getting checkbox validation working</a> on the client side within a MVC project.  This question was successfully answered, but raised another query.</p>
  
  <p>In order for my checkbox validation to work I needed to add the following bits of javascript directly into jquery.validate.unobtrusive.js:</p>
  
  <pre><code>$jQval.addMethod("mustbetrue", function (value, element, param) {
      // check if dependency is met
      if (!this.depend(param, element))
          return "dependency-mismatch";
      return element.checked;
  });
  
  adapters.add("mustbetrue", function (options) {
      setValidationValues(options, "mustbetrue", true);
  });
  </code></pre>
  
  <p>this worked great, but I'm unhappy about having to change this file just in case Microsoft or the validation plugin boys update the file in the future.  If I'm not still working on the project this file may be overwritten without people realising it's been customised. </p>
  
  <p>So with that in mind I tried adding this into an external javascript file:</p>
  
  <pre><code>$.validator.addMethod("mustbetrue", function (value, element, param) {
      // check if dependency is met
      if (!this.depend(param, element))
          return "dependency-mismatch";
      return element.checked;
  });
  
  $.validator.unobtrusive.adapters.add("mustbetrue", function (options) {
      setValidationValues(options, "mustbetrue", true);
  });
  </code></pre>
  
  <p>Unfortunately now the client side script on my checkboxes doesn't run.  Can anyone see what I'm doing wrong?</p>
  
  <p>Thanks in advance</p>
  
  <p>S</p>