Skip to content

Commit

Permalink
Make Category selection list required
Browse files Browse the repository at this point in the history
If $g_allow_no_category is OFF, then use the HTML5 required attribute

Fixes #26686
  • Loading branch information
dregad committed Feb 17, 2020
1 parent 3b60ecf commit e1b5180
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 8 deletions.
11 changes: 8 additions & 3 deletions bug_report_page.php
Expand Up @@ -260,11 +260,12 @@
event_signal( 'EVENT_REPORT_BUG_FORM_TOP', array( $t_project_id ) );

if( $t_show_category ) {
$t_allow_no_category = config_get( 'allow_no_category' );
?>
<tr>
<th class="category" width="30%">
<?php
echo config_get( 'allow_no_category' ) ? '' : '<span class="required">*</span> ';
echo $t_allow_no_category ? '' : '<span class="required">*</span> ';
echo '<label for="category_id">';
print_documentation_link( 'category' );
echo '</label>';
Expand All @@ -274,14 +275,18 @@
<?php if( $t_changed_project ) {
echo '[' . project_get_field( $t_bug->project_id, 'name' ) . '] ';
} ?>
<select <?php echo helper_get_tab_index() ?> id="category_id" name="category_id" class="autofocus input-sm">
<select id="category_id" name="category_id" class="autofocus input-sm" <?php
echo helper_get_tab_index();
echo $t_allow_no_category ? '' : ' required';
?>>
<?php
print_category_option_list( $f_category_id );
?>
</select>
</td>
</tr>
<?php }
<?php
}

if( $t_show_reproducibility ) {
?>
Expand Down
17 changes: 12 additions & 5 deletions core/print_api.php
Expand Up @@ -759,25 +759,32 @@ function print_category_option_list( $p_category_id = 0, $p_project_id = null )
echo '<option value="0"';
check_selected( $p_category_id, 0 );
echo '>';
echo category_full_name( 0, false ), '</option>';
echo category_full_name( 0, false );
echo '</option>', PHP_EOL;
} else {
if( 0 == $p_category_id ) {
if( count( $t_cat_arr ) == 1 ) {
$p_category_id = (int) $t_cat_arr[0]['id'];
} else {
echo '<option value="0"';
echo check_selected( $p_category_id, 0 );
echo '<option value="0" disabled hidden';
check_selected( $p_category_id, 0 );
echo '>';
echo string_attribute( lang_get( 'select_option' ) ) . '</option>';
echo string_attribute( lang_get( 'select_option' ) );
echo '</option>', PHP_EOL;
}
}
}

foreach( $t_cat_arr as $t_category_row ) {
$t_category_id = (int)$t_category_row['id'];
$t_category_name = category_full_name(
$t_category_id,
$t_category_row['project_id'] != $t_project_id
);
echo '<option value="' . $t_category_id . '"';
check_selected( $p_category_id, $t_category_id );
echo '>' . string_attribute( category_full_name( $t_category_id, $t_category_row['project_id'] != $t_project_id ) ) . '</option>';
echo '>';
echo string_attribute( $t_category_name ), '</option>', PHP_EOL;
}
}

Expand Down

0 comments on commit e1b5180

Please sign in to comment.