0

I'm using Jquery validation plugin, everything work fine but when i try to validate the check box i got an error:

TypeError: b is undefined

here's my bootstrap checkbox script:

<div class="col-xs-8">
                    <div class="checkbox icheck">
                        <label>
                            <input type="checkbox" required> I agree to the <a href="#">terms</a>
                        </label>
                    </div>
                </div>

and here's the jquery validation that i used:

$("#formRegister").validate({
            errorElement: "span",
            errorClass: "help-block",
            highlight: function (element, errorClass, validClass) {
                // Only validation controls
                if (!$(element).hasClass('novalidation')) {
                    $(element).closest('.form-group').removeClass('has-success').addClass('has-error');
                }
            },
            unhighlight: function (element, errorClass, validClass) {
                // Only validation controls
                if (!$(element).hasClass('novalidation')) {
                    $(element).closest('.form-group').removeClass('has-error').addClass('has-success');
                }
            },
            errorPlacement: function (error, element) {
                if (element.parent('.input-group').length) {
                    error.insertAfter(element.parent());
                }
                else if (element.prop('type') === 'radio' && element.parent('.radio-inline').length) {
                    error.insertAfter(element.parent().parent());
                }
                else if (element.prop('type') === 'checkbox' || element.prop('type') === 'radio') {
                    error.appendTo(element.parent().parent());
                }
                else {
                    error.insertAfter(element);
                }
            }
Sparky
  • 98,165
  • 25
  • 199
  • 285
Ying
  • 1,282
  • 4
  • 19
  • 34
  • Might not be a bad idea to search through the SO questions tagged with [tag:jquery-validate]... and thoroughly [read the documentation](https://jqueryvalidation.org/reference/). – Sparky Jan 09 '18 at 04:40
  • i always search before posting here fyi. let me know if u found the same problem. thanks. – Ying Jan 09 '18 at 04:42
  • 1
    Yeah, I stopped after I found four of the same... see duplicate links up top. Also, when you read the documentation you'll see [an option called `debug`](https://jqueryvalidation.org/validate/#debug) that would warn you when a field is missing the `name` attribute. – Sparky Jan 09 '18 at 04:56
  • @Sparky thanks. i will take a look of it. – Ying Jan 09 '18 at 04:58

1 Answers1

5

A required input also must have a name. Without a name it won't be submitted by browser and therefore can't also be required

<input name="terms" type="checkbox" required>
charlietfl
  • 170,828
  • 13
  • 121
  • 150