When I try to use a third-party jQuery validation library using Materialize, I cannot validate the selected lists. I was wondering if anyone can or knows how to get jQuery.validation to work with Materialize?
<div class="row">
<div class="input-field col s12 m6">
@Html.DropDownListFor(model =>model.Gender,Models.StaticLists.GenderListItems(), new { @class = "validate[required]", required = "required", Name="Gender"})
<label for="Gender">Gender:<em class="form-req">*</em></label>
</div>
</div>
This will lead to:
<div class="row">
<div class="input-field col s12 m6">
<div class="select-wrapper">
<input type="text" class="select-dropdown required" readonly="true" data-activates="select-options-7a42c777-60c4-6318-3eef-7ff50a96b3a8" value=" " required="required" id="materialGender" name="materialGender" aria-required="true">
<i class="mdi-navigation-arrow-drop-down active"></i>
<select name="Gender" class="validate[required] initialized" data-val="true" data-val-required="The Gender field is required." id="Gender" required="required" aria-required="true">
<option disabled="disabled" selected="selected" value=" "> </option>
<option value="F">Female</option>
<option value="M">Male</option>
</select>
</div>
<label for="Gender" class="">Gender:<em class="form-req">*</em></label>
</div>
</div>
At the end of the body, the ul-li list is displayed:
<ul id="select-options-7a42c777-60c4-6318-3eef-7ff50a96b3a8" class="dropdown-content select-dropdown" style="width: 397px; display: none; top: 558.734375px; left: 315px; height: 134px; opacity: 0;">
<li class="disabled active"><span> </span></li>
<li class=""><span>Female</span></li>
<li class=""><span>Male</span></li>
</ul>
script I use:
$('select').material_select();
$('.select-wrapper input').attr("required", "required").each(function (index, item) {
$selectSibling = $(item).siblings('select');
$(item).attr("id", "material" + $selectSibling.attr("id"));
$(item).attr("name", "material" + $selectSibling.attr("name"));
}).addClass("required");
$("#registerForm").validate({
rules:{
materialGenderType:{
required: true
}
}
});
The result of submitting the form is that all my other form fields that are required and do not fill out are successfully checked. Nothing happens and no errors are displayed with Select Lists. This code is a small example of the functionality I'm trying to provide in my form. Currently, I will not have two lists with the same elements.