Bug 40092

Summary: Adding authorities - clicking save doesn't fill auto-populated fields
Product: Koha Reporter: David Nind <david>
Component: MARC Authority data supportAssignee: Andrii Nugged <nugged>
Status: Signed Off --- QA Contact: Testopia <testopia>
Severity: major    
Priority: P5 - low CC: nugged, ssammons
Version: Main   
Hardware: All   
OS: All   
GIT URL: Change sponsored?: ---
Patch complexity: --- Documentation contact:
Documentation submission: Text to go in the release notes:
This fixes a regression between Koha 24.11, and 25.05 and main. When adding a new authority or bibliogrpaphic record, clicking save (without filling in any fields) now restores filling in the auto-populated fields such as 000, 003, and 008.
Version(s) released in:
Circulation function:
Attachments: Bug 40092: Fill auto-populated control fields in MARC editors
Bug 40092: Fill auto-populated control fields in MARC editors

Description David Nind 2025-06-08 07:47:39 UTC
When adding a new authority record, clicking save (without filling in any fields) doesn't fill in the auto-populated fields such as 000, 003, and 008.

In a 24.11.x instance, this works (start up a local instance or use one of the demos):
1. Authorities > New authority > Topical term
2. Don't enter any information in any fields.
3. Click 'save'.
4. Note that fields such as 000 and 003 are auto-populated
   (not sure if that is the right term).

In 25.05.00 or main, this no longer works:
1. Repeat steps 1 to 3.
2. Note that:
   - fields such as 000 and 003 are not auto-populated
   - the mandatory fields are now highlighted in yellow
   - clicking the individual fields doesn't auto-populate them
Comment 1 David Nind 2025-06-08 07:48:48 UTC
See Mattermost chat discussion  (8 June 2025): https://chat.koha-community.org/koha-community/pl/akiuk7i73b8qmd38haaxrq7z5o
Comment 2 Andrii Nugged 2025-06-10 12:14:11 UTC
We're preparing to upgrade our production to 25.05, so we've been doing thorough beta testing with librarians with our Finnish libraries. During this testing, we discovered that the main MARC records interface is also affected by the same issue. We found why, prepared a fix, and post-checked with librarians that this bug is gone.

The root cause is in the JavaScript function `AreMandatoriesNotOk`, which uses hardcoded rewriting of classes, so it removed recently announced `framework_plugin` calss:

    elt.setAttribute('class',
        'input_marceditor noEnterSubmit '
        + notFilledClass);


so our solution is to expand hardcoded line with the class:

    elt.setAttribute('class',
        'input_marceditor noEnterSubmit framework_plugin '
        + notFilledClass);

or, better yet, or, if that does not creates any other border cases, completely replace the hardcoded class assignment with a more flexible method:

    elt.classList.add(notFilledClass);


Code below.
Comment 3 Andrii Nugged 2025-06-10 12:22:39 UTC
Created attachment 183124 [details] [review]
Bug 40092: Fill auto-populated control fields in MARC editors

Problem: Clicking Save doesn't fill control fields automatically in both the authority and bibliographic MARC editors.

Regression introduced when class `framework_plugin` was added: `AreMandatoriesNotOk()` rewrites the element `class` attribute with a hard‑coded string, dropping existing classes. Because the plugins that populate 000/003/005/008 rely on `framework_plugin`, the inputs are skipped and the fields remain empty.

This patch stops clobbering the attribute and instead appends the visual 'notFilled' class via `elt.classList.add()`. The one-line fix is applied in both `authorities.tt` and `addbiblio.tt`.

Test plan:

Authority editor

1. Authorities → New authority → choose framework (e.g. Topical term).
2. Leave all fields blank, click Save.
   Before patch: 000, 003, 008 remain blank; required tags turn yellow.
3. Apply patch, hard‑refresh, repeat steps 1–2.
   After patch: control fields auto‑populate as in 24.11.

Bibliographic editor

1. Cataloguing → New record (Not in Advanced MARC editor).
2. Click Save without entering data.
   Before patch: control fields stay blank; record cannot be saved.
3. Apply patch, hard‑refresh, repeat.
   After patch: record is blocked, but 000/005/008 auto‑populate.

Both editors behave like 24.11; mandatory highlighting still works.
Comment 4 Andrii Nugged 2025-06-10 12:24:34 UTC
one thing to decide: I put both variants in code, one commented out so we should throw it away if second more elegant (and future-for-new-classes-proof) one is better and works:

// elt.setAttribute('class','input_marceditor noEnterSubmit framework_plugin ' + notFilledClass);

or

.classList.add(notFilledClass);
Comment 5 Shane Sammons 2025-06-11 11:54:46 UTC
I tried the proposed solution as I was also experiencing no auto-population on 000,003,005,and 008 in cataloging coming from 23 to 25.05. I just tried adding a new MARC record and just pressed save (no data entry) and now the fields 000,003,005,and 008 all populate as they did before.

I have the lines commented out as recommended.
Comment 6 David Nind 2025-06-11 12:17:33 UTC
Created attachment 183159 [details] [review]
Bug 40092: Fill auto-populated control fields in MARC editors

Problem: Clicking Save doesn't fill control fields automatically in both the authority and bibliographic MARC editors.

Regression introduced when class `framework_plugin` was added: `AreMandatoriesNotOk()` rewrites the element `class` attribute with a hard‑coded string, dropping existing classes. Because the plugins that populate 000/003/005/008 rely on `framework_plugin`, the inputs are skipped and the fields remain empty.

This patch stops clobbering the attribute and instead appends the visual 'notFilled' class via `elt.classList.add()`. The one-line fix is applied in both `authorities.tt` and `addbiblio.tt`.

Test plan:

Authority editor

1. Authorities → New authority → choose framework (e.g. Topical term).
2. Leave all fields blank, click Save.
   Before patch: 000, 003, 008 remain blank; required tags turn yellow.
3. Apply patch, hard‑refresh, repeat steps 1–2.
   After patch: control fields auto‑populate as in 24.11.

Bibliographic editor

1. Cataloguing → New record (Not in Advanced MARC editor).
2. Click Save without entering data.
   Before patch: control fields stay blank; record cannot be saved.
3. Apply patch, hard‑refresh, repeat.
   After patch: record is blocked, but 000/005/008 auto‑populate.

Both editors behave like 24.11; mandatory highlighting still works.

Signed-off-by: David Nind <david@davidnind.com>
Comment 7 Andrii Nugged 2025-06-11 18:51:31 UTC
Notes for QA phase: we need to decide if `.classList.add(notFilledClass);` is universal and do not interfere/future proof (looks like). If so, then remove another proposed but commented out solution `// elt.setAttribute...`.
Comment 8 David Nind 2025-06-11 20:14:41 UTC
It would also be nice to have a test for this, if it is possible (I have no idea how to create them myself!).

That would help avoid breaking the feature again in the future.
Comment 9 David Nind 2025-06-11 20:15:45 UTC
I changed the status to major, ideally so that this can be fixed in the first maintenance release for 25.05.