Bug 41128

Summary: ratings.js creating "undefined" text for screen readers and print output
Product: Koha Reporter: David Cook <dcook>
Component: OPACAssignee: David Cook <dcook>
Status: Passed QA --- QA Contact: Paul Derscheid <paul.derscheid>
Severity: minor    
Priority: P5 - low CC: paul.derscheid
Version: Main   
Hardware: All   
OS: All   
GIT URL: Initiative type: ---
Sponsorship status: --- Crowdfunding goal: 0
Patch complexity: Trivial patch Documentation contact:
Documentation submission: Text to go in the release notes:
Version(s) released in:
Circulation function:
Bug Depends on: 39706    
Bug Blocks:    
Attachments: Screenshot of "undefined" text in print output
Bug 41128: Only use data rating if it's available
Bug 41128: Only use data rating if it's available
Bug 41128: Only use data rating if it's available

Description David Cook 2025-10-29 05:12:11 UTC
If you try to print the user summary table, you'll likely see a bunch of "undefined" text in the table.

It looks like ./koha-tmpl/opac-tmpl/bootstrap/js/ratings.js iterates through some of the HTML and tries to create spans with text from the data-rating-value attribute, but that attribute doesn't exist, so it uses the text "undefined" instead:

<div class="br-widget br-readonly">
    <a href="#"><span class="sr-only">undefined</span></a>
    <a href="#"><span class="sr-only">undefined</span></a>
    <a href="#"><span class="sr-only">undefined</span></a>
    <a href="#"><span class="sr-only">undefined</span></a>
    <a href="#"><span class="sr-only">undefined</span></a>
</div>
Comment 1 David Cook 2025-10-29 05:19:01 UTC
Created attachment 188544 [details]
Screenshot of "undefined" text in print output
Comment 2 David Cook 2025-10-29 05:26:45 UTC
Created attachment 188545 [details] [review]
Bug 41128: Only use data rating if it's available

This patch prevents span elements being filled with "undefined"
which are then shown to screen readers and print output.

Test plan:
0. Apply the patch
1. Enable the following system preference: OpacStarRatings (results, details, and patron).
2. Check out an item to a user you can log in as (e.g. koha user)
3. Go to /cgi-bin/koha/opac-user.pl in the OPAC
4. Click "Print" on the toolbar above the summary table
5. Note that 5 occurrences of "undefined" do not appear next to the title in the print output
Comment 3 Owen Leonard 2025-10-29 12:18:49 UTC
Created attachment 188547 [details] [review]
Bug 41128: Only use data rating if it's available

This patch prevents span elements being filled with "undefined"
which are then shown to screen readers and print output.

Test plan:
0. Apply the patch
1. Enable the following system preference: OpacStarRatings (results,
   details, and patron).
2. Check out an item to a user you can log in as (e.g. koha user)
3. Go to /cgi-bin/koha/opac-user.pl in the OPAC
4. Click "Print" on the toolbar above the summary table
5. Note that 5 occurrences of "undefined" do not appear next to the
   title in the print output

Signed-off-by: Owen Leonard <oleonard@myacpl.org>
Comment 4 Paul Derscheid 2025-10-31 14:35:31 UTC
Created attachment 188825 [details] [review]
Bug 41128: Only use data rating if it's available

This patch prevents span elements being filled with "undefined"
which are then shown to screen readers and print output.

Test plan:
0. Apply the patch
1. Enable the following system preference: OpacStarRatings (results,
   details, and patron).
2. Check out an item to a user you can log in as (e.g. koha user)
3. Go to /cgi-bin/koha/opac-user.pl in the OPAC
4. Click "Print" on the toolbar above the summary table
5. Note that 5 occurrences of "undefined" do not appear next to the
   title in the print output

Signed-off-by: Owen Leonard <oleonard@myacpl.org>
Signed-off-by: Paul Derscheid <paul.derscheid@lmscloud.de>