Skip to content

Commit

Permalink
Fix handling of "possible values" in "tokens" input
Browse files Browse the repository at this point in the history
It caused all the possible values to be displayed in the HTML, unnecessarily (they went unused), and sometimes caused all the selected values to be rearranged into alphabetical order.

Bug: T302244
Change-Id: I98df3dad48e9a7f6fdcbee577b8b3c988e60c409
  • Loading branch information
yaronkoren committed Jul 10, 2023
1 parent bf99556 commit 77bbf48
Showing 1 changed file with 2 additions and 19 deletions.
21 changes: 2 additions & 19 deletions includes/forminputs/PF_TokensInput.php
Expand Up @@ -183,26 +183,9 @@ public static function getHTML( $cur_value, $input_name, $is_mandatory, $is_disa
}
}

foreach ( $possible_values as $possible_value ) {
if (
array_key_exists( 'value_labels', $other_args ) &&
is_array( $other_args['value_labels'] ) &&
array_key_exists( $possible_value, $other_args['value_labels'] )
) {
$optionLabel = $other_args['value_labels'][$possible_value];
} else {
$optionLabel = $possible_value;
}
$optionAttrs = [ 'value' => $possible_value ];
if ( in_array( $possible_value, $cur_values ) ) {
$optionAttrs['selected'] = 'selected';
}
$optionsText .= Html::element( 'option', $optionAttrs, $optionLabel );
}
foreach ( $cur_values as $current_value ) {
if ( !in_array( $current_value, $possible_values ) && $current_value !== '' ) {
$optionAttrs = [ 'value' => $current_value ];
$optionAttrs['selected'] = 'selected';
if ( $current_value !== '' ) {
$optionAttrs = [ 'value' => $current_value, 'selected' => 'selected' ];
$optionLabel = $current_value;
$optionsText .= Html::element( 'option', $optionAttrs, $optionLabel );
}
Expand Down

0 comments on commit 77bbf48

Please sign in to comment.