1. 程式人生 > 其它 >jquery validate select驗證問題

jquery validate select驗證問題

驗證是通過name進行 鎖定的、

<select id="project_level" name="project_level" class="chosen-select" required>
                                        <option value="">請選擇</option>
                                        <option value="普通">普通</option>
                                        <option value="緊急">緊急</option>
                                        <option value="非常緊急">非常緊急</option>
                                    </select>

  

 

    $("#form1").validate({
                    errorPlacement: function (error, element) {
                      if (element.parent().hasClass("input-group")) {
                         element.parent().after(error);
                      }
                      else{
                        element.after(error)
                      }  
                  },
                  errorPlacement: function (error, element) {
                     error.appendTo(element.parent()); //直接把錯誤資訊加在驗證元素後··
                 },
                    rules: {
                        project_name: { required: true},
                        project_level: {required: true},
                        project_worker: {required: true},
                        project_member: {required: true},
                    },
                    messages: {
                        project_name: {required: "請輸入"},
                        project_level: {required: "請選擇"},
                        project_worker: {required: "請選擇"},
                        project_member: {required: "請選擇"},
                    },
                    ignore:":hidden:not(select)",    //解決select被忽略驗證
                });
                //當選擇改變時,再校驗一次
                $(".chosen-select").change(function(){  
                    $(this).valid();  
                });