Make WordPress Core

Opened 2 weeks ago

Last modified 2 weeks ago

#62549 new enhancement

checked is a boolean attribute

Reported by: kkmuffme's profile kkmuffme Owned by:
Milestone: Awaiting Review Priority: low
Severity: trivial Version:
Component: Administration Keywords:
Focuses: Cc:

Description

https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input/checkbox#checked

but checked='checked' is used in various places.

e.g.

<input class="hide-postbox-tog" name="dashboard_site_health-hide" type="checkbox" id="dashboard_site_health-hide" value="dashboard_site_health" checked='checked'/>Site Health Status

Change History (3)

#1 @yogeshbhutkar
2 weeks ago

Hi @kkmuffme,

Thanks for raising the ticket. I think checked='checked' would work as expected because HTML treats any value for a boolean attribute (including checked="checked", checked="true", or even checked="randomText") as equivalent to the presence of the attribute. (i.e. true/checked)

But considering best practices in mind, we can use (just) checked there.

Source: https://stackoverflow.com/questions/47743629/input-checkbox-checked-by-default

Last edited 2 weeks ago by yogeshbhutkar (previous) (diff)

#2 @ruchirj
2 weeks ago

yes it is right, all the above will result in the checkbox being checked.

<input type="checkbox" checked> ,<input type="checkbox" checked="false">, <input type="checkbox" checked="checked">, <input type="checkbox" checked="true">

#3 @sabernhardt
2 weeks ago

  • Priority changed from normal to low
  • Type changed from defect (bug) to enhancement

HTML coding standards said to use the values such as checked="checked" for each attribute, though an edit in April explicitly added "Omitting the value on boolean attributes is allowed."

Updating __checked_selected_helper() output could be part of a larger project in the admin (ticket:61183#comment:9).

Last edited 2 weeks ago by sabernhardt (previous) (diff)
Note: See TracTickets for help on using tickets.