0
jQuery 유효성 검사를 사용하여 양식의 유효성을 검사하는 양식이 있습니다. 나는 문제를 만났다. 양식이 두 번 유효성이 검사되고 있습니다. 내 변수가 'isValid'두 번jQuery 유효성 검사 : 양식이 두 번 유효성 확인 중입니다.
유효성 검사를 트리거 버튼 후 콘솔에 기록된다 타입 버튼 아래
<button type="button" name="submit" id="submit" vclass="btn btn-default">Submit</button>
에게 규칙이 자바 스크립트입니다 및 사용자에게 표시 될 메시지를 표시합니다. 버튼에 대한 클릭 이벤트도 포함됩니다. 나는 형태에 관한 발견 한 문제의 대부분
$(function() {
$("#createUser").validate({
rules: {
FirstName: "required",
email: {
required: true,
minlength : 2
},
zipCode: {
required: true,
maxlength : 5
},
Telephone: {
required: function (element) {
return $('#options option:selected').val() != "1";
},
maxlength : 12
},
options: {
required: true,
notEqual: "1"
}
},
messages: {
FirstName: "Please specify your first name",
email: {
required: "This email field is required.",
minlength : "email had to have a min length of 2."
},
zipCode: {
required: "Zip code is a required field.",
maxlength : "zip code cannot be more than 5 characters."
},
Telephone: {
required : "Telephone is a required field.",
maxlength : "Phone number has to have a max length of 12 characters."
},
options: {
required: "Option is a required field",
notEqual: "Select a different option"
}
}
});
jQuery.validator.addMethod("notEqual", function (value, element, param) {
return this.optional(element) || value != param;
}, "Please specify a different (non-default) value");
$('#submit').on('click', function() {
isValid = $('#createUser').valid();
console.log(isValid);
});
});
두 번 검증 유형 대신 제출 '버튼을 갖는해야되고. 또한 자바 스크립트 파일의 아무 곳이나 제출하지 않아도됩니다. 내가 여기서 무엇을 놓치고 있니?
내 생각 엔 액션이 바이올린에 twice.Reproduce 구속되고 내가 당신에게 만약 더 –
을주지 것입니다 규칙이 별도의 js에 있으면 스크립트가 두 번 참조되지 않도록합니다. –
@REDEVI_이 문제였습니다. 내 번들에 폴더를 포함합니다. 그런 다음 JavaScript 파일에 대한 참조를 추가하여 해당 폴더가 내 번들에도 포함되어 있음을 잊어 버렸습니다. 댓글을 답으로 변경할 수 있으며 해결 된 것으로 표시하겠습니다. –