【问题标题】:jquery checkbox array validation w/ formwizard带有表单向导的jQuery复选框数组验证
【发布时间】:2010-12-06 17:14:52
【问题描述】:

我正在使用 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>

【问题讨论】:

  • 有 3 个不同的复选框。不知道为什么只有一个出现。其他的 'id' 和 'value' 属性不同,但具有相同的 'name'。

标签: jquery checkbox validation formwizard


【解决方案1】:

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,
    });
});

【讨论】:

  • 好的,谢谢!我曾尝试过类似的方法,只是我没有在属性周围加上引号。哦。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2013-06-14
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2014-04-27
相关资源
最近更新 更多