implementing require_from_group in jquery validate

后端 未结 1 938
暖寄归人
暖寄归人 2021-01-27 16:04

I am trying to get get a group of inputs to validate as one. So if any of the inputs is empty, it will show a message below the inputs. I have been following another SO answer

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

    You're trying to follow an answer that is five years old. Since that time, the default require_from_group method's bugs have been fixed; and the function is presently much more complex than the function you're manually creating.

    So you only need to include the additional-methods.js file to use the default require_from_group method. Otherwise, you could copy this method out of the additional-methods.js file, but IMO, it's better to include the file for future maintainability.

    If that doesn't fix it, you'll need to show us your rendered HTML markup, as seen in the browser source, to check if you've made any other mistakes.

    Working DEMO: http://jsfiddle.net/jo65e26a/


    I am trying to get get a group of inputs to validate as one.

    That is not what require_from_group is meant to do, nor is that how you've configured it...

    require_from_group: [2, ".cc"]
    

    The 2 parameter means that any two inputs out of your group of four will be required. If you need all four to be filled out then you would set the parameter to 4, but then it's absolutely no different than simply using required rule on all four inputs.

    Documentation: require_from_group

    Perhaps you meant to group the validation messages together into one? If so, then you'd use the groups option.

    groups: {
        ccGroup: "cardNumber name expDate cvv"
    }
    

    DEMO 2: http://jsfiddle.net/sx7cda0c/1/


    There is also a method called skip_or_fill_minimum which means that you set a minimum number of fields out of a group to be required, otherwise, the group can be skipped. Not sure if that's what you want either.

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