mardi 29 mars 2016

bootstrap validation for dynamically generated checkboxs is not working ..

Here I wrote bootstrap validation for selecting at least 1 checkbox which is generated dynamically its applicale for only first checkbox, for other checkbox its does not work. plz give me solution.

      <div class="user-all-services-info">
                            <div class="row">
                                <div class="col-md-6">
                                    <div class="form-group">
                                        <label class="control-label">Select Services</label><br>
                                        <c:if test="${!empty servicesList}">
                                            <c:forEach items="${servicesList}" var="services">
                                                <!-- <div class="select-service-option">  -->
                                                <%-- <input type="checkbox" name="servicesId" value="${services.scServiceMstId }" style="margin-left: 10px;margin-top: 7px;">${services.serviceName } --%>

                                                <c:set var="id" scope="page" value="0"></c:set>
                                                <c:choose>
                                                    <c:when test="${!empty serviceMapperList}">
                                                        <c:forEach items="${serviceMapperList}"
                                                            var="serviceMapperList">
                                                            <c:if
                                                                test="${services.scServiceMstId == serviceMapperList[0]}">
                                                                <c:set var="id" value="1"></c:set>
                                                            </c:if>
                                                        </c:forEach>

                                                        <c:choose>
                                                            <c:when test="${id eq 1}">
                                                                <div class="checkbox">
                                                                    <label> <%-- <input type="checkbox"  name="servicesId"  value="${services.scServiceMstId}" style="margin-left: 10px;margin-top: 7px;">&nbsp;${services.serviceName } --%>
                                                                        <input type="checkbox" name="servicesId"
                                                                        value="${services.scServiceMstId}">&nbsp;${services.serviceName }
                                                                    </label>
                                                                </div>

                                                            </c:when>
                                                        </c:choose>

                                                    </c:when>

                                                </c:choose>
                                                <!-- </div>  -->
                                            </c:forEach>
                                        </c:if>
                                    </div>
                                </div>
                            </div>
                        </div>

Above is the code for craeting checkbox dynamically. Its validation code is given below.

        servicesId:{

                                                    validators: {

                                                          notEmpty: {
                                                           message: 'Please select at least 1 service.'
                                                         } 
                                                       /*  choice: {
                                                           min: 1,
                                                            max: 2,
                                                           message: 'Please select at least 1 service.'
                                                       }  */
                                                   }

                                                },




Aucun commentaire:

Enregistrer un commentaire