title: MVC custom DataAnnotation (RequiredAttribute) not applied on select elements
body: <p>I created a new RequiredAttribute extention called "RequredWhen".</p>
  
  <p>It works well on textboxes but not on select elements. 
  For some reason those only validate on postback instead on client side. The "Required" drop downs validate well client side so why aren't the  "RequiredWhen" attributes failing to validate?</p>
  
  <p>When you add this attribute</p>
  
  <pre><code>[Required]
  </code></pre>
  
  <p>You get this markup</p>
  
  <pre><code>&lt;select class="customSelect input-validation-error" data-val="true" data-val-number="The field x must be a number." data-val-range="Please select the correct range" data-val-range-max="5" data-val-range-min="0" data-val-required="The x field is required." id="x" name="x"&gt;&lt;/select&gt;
  </code></pre>
  
  <p>This doesn't happen you add the custom attribute. In the markup all the validation related attributes are missing from the select element (like data-val, etc) but they are applied on input fields.</p>
  
  <p>Is there something additional I need to do to force validation to work on select elements?
  Also the GetClientValidationRules does not include those elements when I debug. I'm sure that's part of the problem.</p>
  
  <p>My attribute extends RequiredAttribute which works on select elements so I am not sure why they are excluded from my implementation. Any ideas? </p>
  
  <p>Here's my javascript which works well on other elements.:</p>
  
  <pre><code>    jQuery.validator.unobtrusive.adapters.add('requiredwhenchecked', [ 'otherproperty', 'checkedproperty', 'otherpropertyvalue' ],function (options) {
      // simply pass the options.params here
      options.rules['requiredWhenChecked'] = options.params;
      }
  );
  
  jQuery.validator.addMethod('requiredWhenChecked', function (value, element, params) {
      return true;
  }, '');
  </code></pre>
  
  <p>There's something that makes this all work well, except for "select" attributes.</p>
  
  <p>I think my problem might be related to <a href="http://aspnet.codeplex.com/workitem/7629" rel="nofollow noreferrer">this</a> and <a href="https://stackoverflow.com/questions/6116764/unobtrusive-dropdown-validation-in-mvc-3">this</a> case which don't seem to have a solution yet</p>
  
  <hr>
  
  <p><strong>UPDATE</strong>
  There IS no solution but there is a workaround and I found it <a href="https://stackoverflow.com/questions/4799958/asp-net-mvc-3-unobtrusive-client-validation-does-not-work-with-drop-down-lists/8102022#8102022">here</a>!
  Good luck to whoever has this nasty problem</p>