Jquery Validate dropdown required if field empty

后端 未结 2 414
野趣味
野趣味 2020-12-30 05:00

I\'m trying to make the dropdown required if the #category field is empty.

Thanks!

JQUERY ATTEMPT #1:

$(\"#uploadDocsForm\").validate({
    r         


        
2条回答
  •  抹茶落季
    2020-12-30 05:36

    I appears that 'depends' is not supported anymore.

    I used the following and it works:

    Notice the option value="" which cause the validation to fail since val is empty

    $("#uploadDocsForm").validate({
        rules: {
            name: {
                required: true,
                minlength: 2,
                maxlength: 255  
            },
            cat_id: {
                required: true
                }
            }
        },
        messages: {
            name: 'Please enter a Document Name.',
            cat_id: 'Please select a Category.'
        }
    });
    

提交回复
热议问题