문제

나는 jQuery를 사용합니다 유효성 검사 플러그인 긍정적 인 사용자가 어떤 사용자가 입력했는지 확인합니다 cost_of_car 첫 번째 텍스트 필드와 긍정적 인 결제 금액 두 번째 텍스트 필드에서 *cost_of_car *0.4 <= payment_amount <= cost_of_car *:

$.validator.addMethod("testMaxAmount", function()
{
    return $("#cost_of_car").val() - 0 >= $("#payment_amount").val() - 0;
}, "Can't be more than cost_of_car");

$.validator.addMethod("testMinAmount", function()
{
    return $("#cost_of_car").val() * 0.4 <= $("#payment_amount").val() - 0;
}, "Can't be less than cost_of_car * 0.4");

$("#calc_form").validate(
{
    rules: 
    {
        cost_of_car: 
        {
            required: true,
            number: true,
            min: 1,
            max: 10000000
        },
        payment_amount: 
        {
            required: true,
            number: true,
            testMaxAmount: true,
            testMinAmount: true 
        }
    }
});

이제 TestMaxAmount 및 TestMinAmount 수표를 건너 뛰고 싶습니다. cost_of_car 유효합니다. 테스트

$("#calc_form").validate().element("#cost_of_car")

또는

$("#calc_form").validate({ignore: "#payment_amount"}).element("#cost_of_car")

이 방법 내부에서 재귀로 이어지고 브라우저가 걸립니다.

유효성 검사를 비활성화하기위한 다른 방법을 제안 하시겠습니까? 결제 금액 ~까지 cost_of_car 유효합니까, 제발?

도움이 되었습니까?

해결책

업데이트: 변화는 validator.addMethod() 전화 :

$.validator.addMethod("testMaxAmount", function()
{
    if($("#cost_of_car").valid())
      return $("#cost_of_car").val() - 0 >= $("#payment_amount").val() - 0;
    else
      return true;
}, "Can't be more than cost_of_car");

$.validator.addMethod("testMinAmount", function()
{
    if($("#cost_of_car").valid())
      return $("#cost_of_car").val() * 0.4 <= $("#payment_amount").val() - 0;
    else
      return true;
}, "Can't be less than cost_of_car * 0.4");
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top