Conditional Validation using JQuery Validation Plugin

后端 未结 3 2019
孤街浪徒
孤街浪徒 2020-12-29 08:57

I have a simple html form that I\'ve added validation to using the JQuery Validation plugin. I have it working for single fields that require a value. I now need to extend t

3条回答
  •  孤城傲影
    2020-12-29 09:37

    You can do something like this:

    $("#editRecord").validate({
        rules: {
            'Details1': {
                required: function() {
                    return $('input[name=Question1]').val() == 'yes';
                }
            }
            'Details2': {
                required: function() {
                    return $('input[name=Question2]').val() == 'yes';
                }
            }
        }
    });
    

提交回复
热议问题