How to customize error message using jQuery.validator placeholders?

前端 未结 1 1940
攒了一身酷
攒了一身酷 2021-01-25 13:43

I\'m trying to add custom form validators. And I\'m stuck with message customizing issue.

Let\'s say I want to check if field value does not exceeds max allowed value. I

相关标签:
1条回答
  • 2021-01-25 14:14

    I cannot comprehend what is responsible for replacing {0} and {1} in '$.validator.format'. And how to pass those parameters?

    In your example above, {0} represents the first parameter and {1} represents the second parameter. The parameters are [5, 6] respectively and the automatic replacement of such within the message is handled automatically by the plugin.

    So when writing a custom method, there is nothing special you'll need to do. If you pass three parameters into your method...

    customMethod: [34, 50, 10]
    

    ...then you'll have {0}, {1}, and {2} available for your custom message, representing each value of the parameters respectively.

    It just works.


    If there is something going wrong, then it's not obvious from your OP aside from:

    The method is called max-numeric, but you're referencing min-numeric in the rules object of the .validate() method.

    As long as you have two parameters next to max-numeric, then your example would work.

    max-numeric: [5, 6]
    
    0 讨论(0)
提交回复
热议问题