I'm using the jQuery validator along with the uniform plugin to fancy up my select elements. The problem is when a select is returned invalid the user doesn't know since the element is hidden. So I'm trying to write a custom method to add the error class to the parent element if the select has an error.
This is what I have so far:
$.validator.addMethod(
"selectvalidate", function(){
if(!$(element).is(':visible')){
return true;
}
else if($(element).val() == "") {
$(element).parent('.selector').addClass('error');
return false;
}
else{
$(element).parent('.selector').removeClass('error');
return true;
}
},
"Please select an option"
);
HTML
<fieldset>
<label>Field Label</label>
<div class="selector"></div>
<span>- Select -</span>
<select>
<option></option>
</select>
</fieldset>
Any help would be great