You are viewing limited content. For full access, please sign in.

Question

Question

Toggling the field required via Java Script

asked on February 15, 2019 Show version history

This is upon Form Load

I have no problem toggling the required off using this:

     $('.req select').removeClass('required').removeAttr('required');
     $('.req textarea').removeClass('required').removeAttr('required');

Results:

The required attribute is gone which is what I want.

The problem is when I toggle it back on.  Instead of required = "True"  it is showing as required = "required"

Using This:

     $('.req select').attr('required', "True");

 

Gets this result:

 

Any ideas as to why this is not required="True"

 

 

 

0 0

Replies

replied on February 15, 2019 Show version history

Hi Barry,

Technically "required" is a boolean attribute meaning the value is not really important and, like with disabled, just the presence of the attribute is enough. My guess is that JQuery just goes with the most universal setup.

It is not uncommon to see required="required" or disabled="disabled" for the sake of consistency because XHTML doesn't support attribute minimization, but in HTML 5 required="required", required="true", and even required="false" are functionally the same.

Technically, you could have any value you want. cheeky

0 0
You are not allowed to follow up in this post.

Sign in to reply to this post.