https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=44328 --- Comment #1 from Adolfo Rodríguez Taboada <adolfo.rodriguez@xercode.es> --- Created attachment 212777 --> https://bugs.koha-community.org/bugzilla3/attachment.cgi?id=212777&action=edit Bug 44328: Clear in the acquisitions item form can create items without a library When items are created on ordering or on receiving, the item form is built by services/itemrecorddisplay.pl with the ACQ framework. Subfields hidden in that framework are still in the form, inside an <li> with display:none, and keep the values set by the server. The home and current library selects default to the logged in library. The "Clear" button (clearItemBlock in additem.js) empties every text input and resets every select of the block to its first option, hidden ones included: - If 952$a or 952$b is not mandatory, its first option is the empty one, so the item is created without a home or current library (items.homebranch or items.holdingbranch is NULL). If the subfield is hidden the user cannot even see it. The record's detail page then fails to load its items table (GET /api/v1/biblios/<id>/items: "DBIC result _type isn't of the _type Branch"). - If it is mandatory, the first library in alphabetical order is picked instead of the logged in library. - Any other hidden subfield loses the value set by the server. Also, attr("selected", true) only changes the attribute, so a select that the user had already changed was not reset by "Clear". This patch makes "Clear" skip the subfields hidden in the framework, and resets each visible select to the default value set by the server (the logged in library for the libraries), or to its first option if there is none. Visible text inputs are emptied as before. Steps to follow: 1. Set the AcqCreateItem system preference to "Placing an order". 2. Go to Administration > MARC bibliographic frameworks > ACQ > MARC structure > 952 > Edit subfields: - a (Home library): untick all the Visibility checkboxes (OPAC, Staff interface, Editor, Collapsed) and untick Mandatory. - b (Current library): leave it visible and untick Mandatory. Save. 3. Go to Acquisitions, open a basket of any vendor and add an order "From a new (empty) record". Fill in a title. 4. In the item block, click "Clear", choose an item type and click "Add item". Fill in the order fields and save. 5. Open the detail page of the record: the items table fails to load, and the item has no home library and no current library in the database. 6. Apply the patch and reload the page without cache (Ctrl+Shift+R). 7. Repeat steps 3 and 4. Before clicking "Clear", change the current library and the shelving location: "Clear" sets the current library back to the logged in library and the shelving location back to its first option. 8. Open the detail page of the record: the items table loads, and the item has the logged in library as home and current library. 9. Optional: make 952$a and 952$b mandatory again (the default), change both libraries and click "Clear": both go back to the logged in library (before the patch, the first library in alphabetical order). -- You are receiving this mail because: You are watching all bug changes.