Jquery-validation: input with required="false" have a value required

Created on 26 Nov 2018  Â·  4Comments  Â·  Source: jquery-validation/jquery-validation

Subject of the issue

When setting an input with required="false", a value is required.

Your environment

  • version of jquery-validate: 1.18.0
  • which browser and its version: firefox 63.0.3

Steps to reproduce

add an input tag with required="false". On validation, it will be required to have a value (which should not be the case).

Expected behaviour

an input with required="false" should not have its value required.

Actual behaviour

The value is required.

To correct this, in the attributeRules function, the test should be :
if ( value === "" ) {
value = true;
}
else if ("false" === value) {
value = false;
}

Bug Core help wanted

Most helpful comment

Yeah, I don't think "false" is valid:

From the W3 docs for the required attribute,

The required attribute is a boolean attribute. When specified, the element is required.

And for the definition of a "boolean attribute",

The presence of a boolean attribute on an element represents the true value, and the absence of the attribute represents the false value.

If the attribute is present, its value must either be the empty string or a value that is an ASCII case-insensitive match for the attribute’s canonical name, with no leading or trailing white space.

The values "true" and "false" are not allowed on boolean attributes. To represent a false value, the attribute has to be omitted altogether.

So it's either required="required" or simply required, but required="true" or required="false" are not expected.

All 4 comments

Hi @eproffit,

Thanks a lot for filling this issue! I'll take a look at it as soon as possible!

Hi all,

If anyone is interested in writing a patch for this issue, I'd be more than happy to walk you through the steps involved, as I can't work on it at the moment.

Thanks!

An input tag with required(whatever ' required="true" ' or ' required="false" ' ).it will be required to have a value.This is the case in HTML.

Yeah, I don't think "false" is valid:

From the W3 docs for the required attribute,

The required attribute is a boolean attribute. When specified, the element is required.

And for the definition of a "boolean attribute",

The presence of a boolean attribute on an element represents the true value, and the absence of the attribute represents the false value.

If the attribute is present, its value must either be the empty string or a value that is an ASCII case-insensitive match for the attribute’s canonical name, with no leading or trailing white space.

The values "true" and "false" are not allowed on boolean attributes. To represent a false value, the attribute has to be omitted altogether.

So it's either required="required" or simply required, but required="true" or required="false" are not expected.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

davesierra picture davesierra  Â·  7Comments

Bek81 picture Bek81  Â·  3Comments

harkinj picture harkinj  Â·  8Comments

ricardopolo picture ricardopolo  Â·  8Comments

starchild picture starchild  Â·  3Comments