jQuery Validation - same rule depending on values

前端 未结 1 692
耶瑟儿~
耶瑟儿~ 2021-01-27 10:52

I\'m having trouble with the syntax to get 2 range values on an input field validation.

My form has 2 select fields and one text input field.

If select1 =

相关标签:
1条回答
  • 2021-01-27 11:11

    Only one will work at any one time.

    Because you cannot have the same rule declared twice on the same field. The second will likely over-ride the first.

    Also, the way you've written it using the depends, you're saying you only want the range rule when the condition is met.

    You simply need to use a function to return the parameter depending on the conditional.

    PrepurchasePlotNumber: {
        digits: true,
        range: function() {
            if (($("#PrepurchasePlotArea").val() == "1") && ($("#PrepurchasePlotRow").val() == "A")) {
                return [1, 120]
            } else {
                return [121, 500]
            }   
        },
        ....
    

    Modify logic as needed.

    0 讨论(0)
提交回复
热议问题