jquery 复选框数组验证 w/formwizard

标签 jquery checkbox validation formwizard

我正在使用 formwizard 插件,但无法获取复选框数组进行验证。我已经在页面上运行了其他元素,但无法获取此元素(更不用说这是我需要的 2 个复选框数组之一)。必须选择一项或多项。我已将页面缩减为我希望对这个问题至关重要的部分。

<input type="checkbox" name="status_checkbox[]" id="status_professional" value="status_professional">

    <script type="text/javascript">
    $(function(){
        $("#infoForm").formwizard({ 
            formPluginEnabled: true,
            validationEnabled: true,
            validationOptions : {
                rules: {
                    status_checkbox: {
                        //required: "input[name='status_checkbox[]']",
                        required: "input[name='status_checkbox:checked']",
                        minlength: 1
                    },
                },
                messages: {
                    status_checkbox: {
                        required: "Status field is required."
                    },
                }
            },
            focusFirstInput : true,
        });
    });
</script>

最佳答案

name 需要是您在规则中使用的键,因此 status_checkbox 需要是 status_checkbox[],如下所示:

$(function(){
    $("#infoForm").formwizard({ 
        formPluginEnabled: true,
        validationEnabled: true,
        validationOptions : {
            rules: {
                "status_checkbox[]": {
                    required: true,
                    minlength: 1
                },
            },
            messages: {
                "status_checkbox[]": {
                    required: "Status field is required."
                },
            }
        },
        focusFirstInput : true,
    });
});

关于jquery 复选框数组验证 w/formwizard,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4369058/

相关文章:

php - 在 Laravel 中自定义模型存储的验证规则

jquery - "freezing"一个输入框

asp.net-mvc - jQuery 中 $.getJSON() 和 $.ajax() 之间的区别

javascript - 为什么 $(window).width() 在页面加载时发生变化?

jquery - 如何使用 JQuery 从 Bootstrap 轮播中删除特定幻灯片

javascript - 第一次单击复选框时不调用函数

arrays - Mongoose 模式需要可以为空的数组

c# - INT 在复选框中转换为可更新的 bool 值

适用于 Firefox、Chrome、IE8 的 Android 复选框

spring - @Autowired 验证器内的 DAO