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);
                }
            }
4
  • Might not be a bad idea to search through the SO questions tagged with jquery-validate... and thoroughly read the documentation. Commented Jan 9, 2018 at 4:40
  • i always search before posting here fyi. let me know if u found the same problem. thanks. Commented Jan 9, 2018 at 4: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 that would warn you when a field is missing the name attribute. Commented Jan 9, 2018 at 4:56
  • @Sparky thanks. i will take a look of it. Commented Jan 9, 2018 at 4:58

1 Answer 1

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>
Sign up to request clarification or add additional context in comments.

3 Comments

it work but why it doesn't have a red color like the other input?
No idea....... .Create a minimal reproducible example if that's a problem also
i think i have to modify it in the errors placements. i think i just have to find the right parents for the errors class. thanks,

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.