는 HTML 코드 조각의 샘플은 여기 요소를 사용할 경우에도 요소 검증을 실패 :jQuery를 검증 플러그인은
<select name="paytitle" id="paytitle">
<option value="Budget Keeper" selected>Budget Keeper</option>
<option value="Bookkeeper">Bookkeeper</option>
<option value="Treasurer">Treasurer</option>
<option value="Accounts Payable">Accounts Payable</option>
<option value="Other">Other</option>
</select>
<div id="otherfield">Other: <input name="paytitleother" type="text" id="paytitleother" class="required" /></div>
내가 선택 값을 기준으로 paytitleother 필드를 비활성화하고 숨기는 기능을 가지고 :
$('#paytitle').change(function() {
if ($(this).val() == 'Other')
{
$("#paytitleother").removeAttr("disabled");
$("#otherfield").css("display", "block");
} else {
$("#paytitleother").attr("disabled", true);
$("#otherfield").css("display", "none");
}
});
양식을 제출하려고 할 때 paytitleother 필드가 비활성화되어 숨겨져 있어도 유효성 검사가 실패합니다. 검증에 대한 문서는 플러그인 상태를 사용할 수없는 모든 필드는 자동으로 무시됩니다하지만 유효성 검사 루틴에 ignore: ":disabled"
를 추가하는 추가 단계를 갔다 :
$('#fieldForm').validate({
ignore: ':disabled',
...
});
에도이 사양 필드의 유효성 검사가 실패합니다. 나는 하루 종일이 프로젝트에서 일해 왔기 때문에 나는 단순한 것을 간과 할 가능성이 있지만 그것을 볼 수없고 나에게 일어난 일을 짐작할 수 없다.
감사합니다 - 나는 어떤 메소드 (true 대 "disabled")를 사용하는지 충돌 정보를 읽었으며 가능하면 프런트 엔드 개발에서 벗어나려고 노력합니다. 내 모든 문제를 해결하기 위해 숨겨진 모든 요소의 초기 상태를 비활성화합니다. –