Expand collapsible div on validation

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

  1. <script type="text/javascript">
  2.    $(document).ready(function () {
  3.        $('#mastercardForm').validate({
  4. invalidHandler: function(form, validator) {
  5.         if (validator.numberOfInvalids() > 0) {
  6. validator.showErrors();
  7. if ($('label.error').css('display') != 'none')
  8. {
  9. var myindex = $('label.error').closest('div.ui-collapsible').index('.myDiv');
  10. alert(myindex);
  11. $('myDiv').trigger('expand', myindex);
  12. alert(validator.numberOfInvalids());
  13. }
  14.         }
  15.     },
  16.           ignore: "hidden",
  17.            rules: {
  18.                'rad_Type_of_Account': { required: true },
  19.               ApplicantInitial: {
  20.                    required: {
  21.                        depends: function () {
  22.                            return $('input[name=rad_Type_of_Account]:checked').val() == 'Joint';
  23.                        }
  24.                    }
  25.                },
  26.                JointInitial: {
  27.                    required: {
  28.                        depends: function () {
  29.                            return $('input[name=rad_Type_of_Account]:checked').val() == 'Joint';
  30.                        }
  31.                    }
  32.                },
  33. 'rad_Accept': { required: true },
  34.                name: "App_FName", // simple rule, converted to {required:true}
  35.                name: "App_LName"
  36.            }
  37.        });
  38.    });
  39.    });

  40. </script>