jquerycheckboxvalidationformwizard

jquery checkbox array validation w/ formwizard


I'm using the formwizard plugin and I can't get a checkbox array to validate. I've got other elements on the page working, but can't get this one (not to mention this is one of 2 checkbox arrays I'll need). There must be one or more items selected. I've chopped the page down to what I hope is essential for this question.

<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>

Solution

  • The name needs to be they key you use in the rules, so status_checkbox needs to be status_checkbox[], like this:

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