2017-02-08 3 views
0

이 작업은 복잡한 작업이 아니지만 직접 수행 할 수는 없습니다. 나는 너의 도움에 대해 대단히 감사한다.입력 필드가 비어있을 때 jQuery 유효성 검사가 작동하지 않습니다.

나는 유효성 확인과 함께 양식을 제출할 예정입니다. 내 유효성 검사가 제대로 작동하지 않는 것 같습니다. 왜냐하면 입력 필드가 비어 있으면 오류 메시지가 표시되지 않기 때문입니다. 제출 버튼을 클릭 할 때 오류 메시지가 표시되지 않습니다. 이 사건은 입력 필드가 비어있을 때만 발생합니다. 이 같은 핸들러 뭔가를 제출

<input type="submit" value="Register" class="btn pull-right" id="btnsubmit" style="background-color:#1e90ff; width: 100px; color: white; font-weight: bold" /> 

을 그리고합니다

모두의
$('#department').validate({ 
    rules: { 
     textDepartmentName1: { 
      required: true, 
      minlength: 3, 
     }, 
     textRegistationNumber: { 
      required: true, 
      minlength: 3 
     }, 
     textWebsite1: { 
      required: true, 
      minlength: 3 
     } 

    }, 
    submitHandler: $("#btnsubmit").click(function (form) { 
     var submitData = { 
      DepartmentId: saveStat, 
      DepartmentName: $('#textDepartmentName').val().trim(), 
      RegistationNumber: $('#textRegistationNumber').val(), 
      Website: $('#textWebsite').val(), 
      Email: $('#textEmail').val(), 
      Telephone01: $('#textTelephone01').val(), 
      Telephone02: $('#textTelephone02').val(), 
      Fax: $('#textFax').val(), 
      BranchId: $('#cmbGetBranch').val() 
     } 

     if (saveStat == 0) { 
      $.ajax({ 
       dataType: 'json', 
       contentType: 'application/json; charset=utf-8', 
       cache: false, 
       async: false, 
       type: 'POST', 
       data: "{submitData:" + JSON.stringify(submitData) + "}", 
       url: "/Department/AddDepartment", 
       success: function (saveDepartment) { 
        if (saveDepartment.saveDepartment.DepartmentId != 0) { 
         refresh(); 
         alert(saveDepartment.saveDepartment.DepartmentName + " Saved succesfully...!!!"); 
        } else { 
         alert('warning' + " Department saving unsucsessful...!!!"); 

        } 
       }, 
       error: function (xhr, errorThrown) { 
        alert('Error...!!! Internal - 01'); 
       } 

      }); 
     } else { 
      $.ajax({ 
       dataType: 'json', 
       contentType: 'application/json; charset=utf-8', 
       cache: false, 
       async: false, 
       type: 'POST', 
       data: "{submitData:" + JSON.stringify(submitData) + "}", 
       url: "/Department/UpdateDepartment", 
       success: function (updateDepartment) { 
        if (updateDepartment.updateDepartment.DepartmentId != "") { 
         alert(updateDepartment.updateDepartment.DepartmentName + " updated succesfully...!!!"); 
         refresh(); 
        } else { 
         alert("Department update error...!!!"); 
        } 
       }, 
       error: function (xhr, errorThrown) { 
        alert('Error...!!!'); 
       } 
      }); 
     } 
     grid(); 
    }) 
}); 
+0

입력 된 HTML에'required'를 전달해야한다고 생각합니다. –

+0

어떻게 할 수 있습니까? –

+0

그냥 필수 속성을 추가했지만 작동하지 않습니다. –

답변

1

먼저 제출 buttom의 유형을 등록합니다 jQuery를

<form name="department" id="department"> 
    <div class="form-group"> 
     <label for="example-text-input">Department Name</label> 
     <span id="errfnCustomer"></span> 
     <input class="form-control" type="text" placeholder="Enter Department Name" id="textDepartmentName" name="textDepartmentName1"> 
    </div> 
    <div class="form-group"> 
     <label for="example-text-input">Registation Number</label> 
     <span id="errfnCustomer2"></span> 
     <input class="form-control" type="text" placeholder="Enter Department Registation Number" id="textRegistationNumber" name="textRegistationNumber"> 
    </div> 
    <div class="form-group"> 
     <label for="example-text-input">Web Site</label> 
     <input class="form-control" type="text" placeholder="Web Site" id="textWebsite" name="textWebsite1"> 
    </div> 
    <div class="form-actions"> 
     <div class="form-group"> 
      <input type="button" value="Register" class="btn pull-right" id="btnsubmit" style="background-color:#1e90ff; width: 100px; color: white; font-weight: bold" /> 
     </div> 
    </div> 
</div> 

그리고 다음은

내 HTML입니다 :

submitHandler:function (form) { 

} 

자세히보기 (Jquery validation).

+0

이것은 대답이 아니다 ... 이것은 코멘트이어야한다 – Gags

+0

이것은 답이다. 나는 이것을 단지 업데이트하고있다. –

+0

답변이 완료되지 않은 한 게시하지 마십시오. – Gags

관련 문제