Expand collapsible div on validation
I have six JQM divs on the page that look like this:
<div class="myDiv" name="accordion" data-role="collapsible">
the first div collapsible is set to false (data-collapsed="false")
On validation I want to expand the next closest div. In my script I’m looking for the label with the class.error and getting the index of the closest div. My alert shows the myindex which displays the right number of the next error array however I can’t get the div with the next error to expand. I was trying to trigger the expand with the index of the div.
Here is my jquery
-
<script type="text/javascript">
-
$(document).ready(function () {
-
-
$('#mastercardForm').validate({
-
invalidHandler: function(form, validator) {
-
if (validator.numberOfInvalids() > 0) {
-
validator.showErrors();
-
if ($('label.error').css('display') != 'none')
-
{
-
var myindex = $('label.error').closest('div.ui-collapsible').index('.myDiv');
-
alert(myindex);
-
$('myDiv').trigger('expand', myindex);
-
alert(validator.numberOfInvalids());
-
}
-
}
-
},
-
-
ignore: "hidden",
-
rules: {
-
'rad_Type_of_Account': { required: true },
-
ApplicantInitial: {
-
required: {
-
depends: function () {
-
return $('input[name=rad_Type_of_Account]:checked').val() == 'Joint';
-
}
-
}
-
},
-
JointInitial: {
-
required: {
-
depends: function () {
-
return $('input[name=rad_Type_of_Account]:checked').val() == 'Joint';
-
}
-
}
-
},
-
'rad_Accept': { required: true },
-
-
name: "App_FName", // simple rule, converted to {required:true}
-
name: "App_LName"
-
}
-
-
});
-
});
-
});
</script>