Validating multiselect with jquery validation plugin

后端 未结 2 1755
青春惊慌失措
青春惊慌失措 2020-12-21 09:15

Trying to figure out why my recipient multiselect isn\'t validating on form submission. Should be atleast 1 person chosen. I have it set to be required true but yet its stil

2条回答
  •  没有蜡笔的小新
    2020-12-21 09:46

    The accepted answer doesn't work anymore. The problem is that the "getChecked" argument doesn't do anything anymore. Here is an updated, working version of the validation method

    $.validator.addMethod("needsSelection", function (value, element) {
                    var count = $(element).find('option:selected').length;
                    return count > 0;
                })
    

提交回复
热议问题