Make WordPress Core

Opened 9 years ago

Closed 5 months ago

#39952 closed defect (bug) (worksforme)

Category Dropdown Widget: required spacing issue on attachments template

Reported by: tribalnerd's profile tribalNerd Owned by:
Milestone: Priority: normal
Severity: normal Version: 4.7.2
Component: Widgets Keywords: reporter-feedback
Focuses: Cc:

Description

This issue only happens on the attachments.php template, all other primary templates don't appear to have the issue.

When using the category widget as a dropdown, the select statement looks like: <selectname='cat' rather than <select name='cat'

The file, category-template.php output statement is:

<?php
$output = "<select $required name='$name' id='$id' class='$class' $tab_index_attribute>\n";

Removing $required corrects the issue.

Setting required to true also corrects the issue.

<?php
function categories_dropdown($args) {
    $args['required'] = true;
    return $args;
}
add_filter( 'widget_categories_dropdown_args', 'categories_dropdown' );

Which returns:

<select required="" name="cat" id="cat" class="postform">

While this does correct the issue, the required="" isn't correct either, it should be: required without the =""

https://developer.mozilla.org/en-US/docs/Web/HTML/Element/select

It should also have aria-required="true" for Safari.

Change History (3)

#1 in reply to: ↑ description @subrataemfluence
9 years ago

  • Keywords reporter-feedback added

Would you mind telling how to reproduce the issue? An example code would be handy.

Replying to tribalNerd:

This issue only happens on the attachments.php template, all other primary templates don't appear to have the issue.

When using the category widget as a dropdown, the select statement looks like: <selectname='cat' rather than <select name='cat'

The file, category-template.php output statement is:

<?php
$output = "<select $required name='$name' id='$id' class='$class' $tab_index_attribute>\n";

Removing $required corrects the issue.

Setting required to true also corrects the issue.

<?php
function categories_dropdown($args) {
    $args['required'] = true;
    return $args;
}
add_filter( 'widget_categories_dropdown_args', 'categories_dropdown' );

Which returns:

<select required="" name="cat" id="cat" class="postform">

While this does correct the issue, the required="" isn't correct either, it should be: required without the =""

https://developer.mozilla.org/en-US/docs/Web/HTML/Element/select

It should also have aria-required="true" for Safari.

#2 @sabernhardt
5 years ago

  • Component changed from General to Widgets

The spacing issue may have been fixed by now; I don't see a problem with it on Twenty Ten's attachment page. If you still see the spacing problem, could you mention which theme you use?

Default category dropdown:
<select name='cat' id='cat' class='postform' >

Category dropdown after applying filter:
<select required name='cat' id='cat' class='postform' >

The required attribute does not have the equal sign in the markup, but it does appear as required="" when inspecting the element within the browser.

Support should be better now for the required attribute, though the aria-required attribute could be good to add anyway.

#3 @sabernhardt
5 months ago

  • Milestone Awaiting Review deleted
  • Resolution set to worksforme
  • Status changed from new to closed

I tried this again with Twenty Twenty-One, and the select element had spaces between each attribute.

Without the required attribute:
<select name='cat' id='cat' class='postform'>

Adding $args['required'] = true; in the widget_categories_dropdown_args filter:
<select required name='cat' id='cat' class='postform'>

Also, tickets such as #39045 and #43415 have removed aria-required when the element has required.

Note: See TracTickets for help on using tickets.