Skip to content

Commit

Permalink
Show all empty stars on empty rating (#1970)
Browse files Browse the repository at this point in the history
This PR Closes #1906. 

There was no strict checking, so `false` was evaluated as `0` (`+ 1 =
1`).
  • Loading branch information
zackkatz authored Jan 16, 2024
2 parents 17f03e1 + bd3f747 commit 3423dd9
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 2 deletions.
1 change: 1 addition & 0 deletions readme.txt
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ Beautifully display your Gravity Forms entries. Learn more on [gravitykit.com](h
This release makes it easier to customize search results per-View instead of globally using code.

* Fixed: Sorting the View by entry ID in ascending and descending order would yield the same result
* Fixed: Survey fields without a rating would show a 1-star rating

__Developer Updates:__

Expand Down
6 changes: 4 additions & 2 deletions templates/fields/field-survey-html.php
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,9 @@
$choices = $field->field->choices;
$choice_values = wp_list_pluck( $choices, 'value', $gravityview->value );
$starred_index = array_search( $gravityview->value, $choice_values );
$star_a11y_label = sprintf( __( '%s (%d out of %d stars)', 'gk-gravityview'), $choice_text, ( $starred_index + 1 ), sizeof( $choice_values ) );
$star_a11y_label = $starred_index !== false
?sprintf( __( '%s (%d out of %d stars)', 'gk-gravityview'), $choice_text, $starred_index + 1, count( $choice_values ) )
: '';

/**
* @action `gravityview/field/survey/rating-styles`
Expand All @@ -162,7 +164,7 @@
foreach ( $choices as $current_index => $choice_value ) {

// Have we already shown the last filled-in star?
$empty = ( $current_index > $starred_index );
$empty = ( $starred_index === false || $current_index > $starred_index );
$css_class = 'gv-field-survey-star-' . ( $empty ? 'empty' : 'filled' );

echo sprintf( '<span class="%s" title="%s"></span>', esc_attr( $css_class ), esc_attr( $choice_value['text'] ) );
Expand Down

0 comments on commit 3423dd9

Please sign in to comment.