I want to use jQuery validate library on a div based select form element. I am using the dropkick library to beautify my selects, but I am having difficulties trying to validate the form due to my select elements getting re-created with DIVS.
<select id="permissionGroup" class="dropkick" name="permissionGroup" style="display: none;">
<option selected="selected" value="">
Please Select
</option>
<option value="1">
Admin
</option>
<option value="2">
Auditor
</option>
</select>
The above select field will get converted into the below html.
<div id="dk_container_permissionGroup" class="dk_container dk_theme_default" tabindex="" style="display: block;">
<span class="value"><a class="dk_toggle" style="width: 131px;"><span class=
"dk_label">Please Select</span></a></span>
<div class="dk_options" style="top: 29px;">
<ul class="dk_options_inner">
<li class="dk_option_current"><a data-dk-dropdown-value="">Please Select</a></li>
<li class=""><a data-dk-dropdown-value="1">Admin</a></li>
<li class=""><a data-dk-dropdown-value="2">Auditor</a></li>
</ul>
</div>
I built the following custom method for validator, but not sure how to apply it to the form validation process.
$.validator.addMethod(
"permissionGroupCheck",
function(value, element){
var spanValue = $("#dk_container_permissionGroup span.dk_label").text();
if(spanValue == "Please Select"){
return false;
}else{
return true;
}
}
);