From 2f5222fee505d1e52ebe4dc3bdda572eea8030ce Mon Sep 17 00:00:00 2001 From: Martin Renvoize Date: Sat, 28 Feb 2026 17:13:51 +0000 Subject: [PATCH] Bug 35104: Show nonxml_stripped errors in edit form with quick-links to fields When a biblio being edited has existing nonxml_stripped error rows in biblio_metadata_errors, display them in a 'Data quality warnings' alert banner above the MARC editor. Each error entry includes a 'Go to field' quick-link that switches to the correct tab and scrolls to the first occurrence of the affected subfield so the cataloguer can inspect and correct the data. Sponsored-by: OpenFifth --- cataloguing/addbiblio.pl | 29 ++++++++++++++++ .../prog/en/modules/cataloguing/addbiblio.tt | 34 +++++++++++++++++++ 2 files changed, 63 insertions(+) diff --git a/cataloguing/addbiblio.pl b/cataloguing/addbiblio.pl index 4bb600a029a..144095b30c2 100755 --- a/cataloguing/addbiblio.pl +++ b/cataloguing/addbiblio.pl @@ -681,6 +681,35 @@ if ($biblionumber) { } } +# Load any existing nonxml_stripped errors so they can be shown in the edit form +# with quick-links to the affected fields. +if ( $biblio && $is_a_modif ) { + my @existing_errors = $biblio->metadata->metadata_errors->search( { error_type => 'nonxml_stripped' } )->as_list; + if (@existing_errors) { + $template->param( + existing_nonxml_errors => [ + map { + my $msg = $_->message; + + # First line is "TAG$sub: invalid char ..." – extract tag/subfield + my ($field_ref) = $msg =~ /^(\S+?):/; + my ( $tag, $subfield ) = + $field_ref && $field_ref =~ /^(\w+)\$(\w)$/ ? ( $1, $2 ) + : $field_ref ? ( $field_ref, undef ) + : ( undef, undef ); + { + id => $_->id, + message => $msg, + field_ref => $field_ref // '', + tag => $tag // '', + subfield => $subfield // '', + } + } @existing_errors + ] + ); + } +} + #------------------------------------------------------------------------------------- if ( $op eq "cud-addbiblio" ) { diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/cataloguing/addbiblio.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/cataloguing/addbiblio.tt index 46d4827e9a8..dea2d4911ad 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/cataloguing/addbiblio.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/cataloguing/addbiblio.tt @@ -193,6 +193,21 @@ document.getElementById("form-errors").scrollIntoView(); }); + $("body").on("click", ".nonxml-linkfield", function(e){ + e.preventDefault(); + var tag = $(this).data("tag"); + var sub = $(this).data("subfield") || "@"; + // Find the first subfield_line for this tag+subfield (random suffix unknown) + var $li = $('li[id^="subfield' + tag + sub + '"]').first(); + if ( !$li.length ) return; + // Determine which tab contains the field + var $tabpane = $li.closest(".tab-pane"); + if ( $tabpane.length ) { + selectTab("#" + $tabpane.attr("id")); + } + window.scrollTo(0, getScrollto($li.attr("id"), "toolbar")); + }); + }); function selectTab( tablink ){ @@ -798,6 +813,25 @@ [% END #/ WRAPPER sub-header.inc %] [% WRAPPER 'main-container.inc' wide_centered => 1 %] + [% IF existing_nonxml_errors %] +
+

Data quality warnings

+

Non-XML characters were automatically stripped from this record when it was last saved. Please review the affected fields and correct or confirm the data.

+ +
+ [% END %] [% IF ( INVALID_METADATA ) %]

Errors found

-- 2.53.0