Jquery validation plugin rule
<p>I need help in writing the jquery validation rule (i am using Jquery Validation Plugin) for following scenario.</p>

<p>Below is scenario...</p>

<p>Based on first dropdown value, second dropdown will be enabled. And we need to make selection from second dropdown and add it to table using Add button.</p>

<p>Validation rule should be like below.</p>

<p><strong>If first dropdown selection enabled the second dropdown, but non of the value from second dropdown is added to table (i mean table is empty), then we need to show error message against second dropdown while hitting submit button in the form.</strong></p>

<p>I tried adding attr like "data-rule-{addmethod_rulename}" to second dropdown and wrote custom addmethod rule using first dropdown value and table size, but it is not working.</p>

<p>JSP code:</p>

<pre><code>&lt;form ....&gt;
:
:
:
    &lt;b:form-group label="${firstdropdown}" labelFor="firstdropdown" cssBody="col-sm-2" cssClass="required"&gt;
        &lt;form:select path="firstdropdown" name="firstdropdown" class="form-control" required="required"&gt;
            &lt;form:option value="" label=""/&gt;
            &lt;form:options items="${firstdropdownvalues}"/&gt;    {This items has two values - One will disable below dropdown and another will enable}.
        &lt;/form:select&gt;
    &lt;/b:form-group&gt;
:
:
:
    &lt;b:form-group label="${seconddropdown}" labelFor="seconddropdown" cssBody="col-sm-4" cssClass="required"&gt;
        &lt;div class="form-inline"&gt;
            &lt;select name="seconddropdown" class="form-control" disabled&gt;
                &lt;option value=""&gt;&lt;/option&gt;
                &lt;c:forEach items="${values}" var="dropdown"&gt;
                    &lt;option value="${dropdown.name}"&gt;${dropdown.name}&lt;/option&gt;    {This items will have several values - we can select one by one and add it to below table using this addsite button}.
                &lt;/c:forEach&gt;
            &lt;/select&gt;
            &lt;button id="addbtn" type="button" class="btn btn-primary" disabled&gt;&lt;spring:message code="form.button.platform.addbtn"/&gt;&lt;/button&gt;
        &lt;/div&gt;
    &lt;/b:form-group&gt;
:
:
:
    &lt;b:form-group cssBody="col-sm-6"&gt;
        &lt;table id="pfmtable" class="table table-striped table-bordered dt-responsive"&gt;
            &lt;thead&gt;
                &lt;tr&gt;
                    &lt;th&gt;&lt;input name="select_all" type="checkbox"/&gt;&lt;/th&gt;
                    &lt;th&gt;Sites&lt;/th&gt;
                &lt;/tr&gt;
            &lt;/thead&gt;
            &lt;tbody&gt;
            &lt;/tbody&gt;
        &lt;/table&gt;
    &lt;/b:form-group&gt;
:
:
:
&lt;/form&gt;
</code></pre>

<p>Javascript code:</p>

<pre><code>jQuery.validator.addMethod("isadded", function(value, element) {
    return $('#firstdropdown').val() == 'Enable_Value' &amp;&amp; $("#pfmtabletr").length &gt; 0;
}, "* Atleast one site should be selected");


$('button:submit').click(function(){
                    var name = $('#name').val();
                    var $form = $('form');
                    $form.validate({
                        rules:{
                            seconddropdown: {isadded: true}
                        },
                        highlight: function(element) {
                            $(element).closest('.form-group').addClass('has-error');
                        },
                        unhighlight: function(element) {
                            $(element).closest('.form-group').removeClass('has-error');
                        }, 
</code></pre>