Bug 32204

Summary: in-page anchor to edititem on additem.pl not working
Product: Koha Reporter: Lucas Gass <lucas>
Component: CatalogingAssignee: Lucas Gass <lucas>
Status: RESOLVED FIXED QA Contact: Testopia <testopia>
Severity: normal    
Priority: P5 - low CC: barbara.johnson, emily.lamancusa, m.de.rooy, nick, wizzyrea
Version: Main   
Hardware: All   
OS: All   
Change sponsored?: --- Patch complexity: Trivial patch
Documentation contact: Documentation submission:
Text to go in the release notes:
Version(s) released in:
23.05.00,22.11.03
Attachments: Bug 32204: Check for hash before setting focus
Bug 32204: Check for hash before setting focus
Bug 32204: Check for hash before setting focus

Description Lucas Gass 2022-11-14 23:56:32 UTC
To recreate:

1. Search the catalog and view a record detail page of a record with items
2. Click 'Edit items'
3. Choose one item from the list and click 'Edit'
4. The URL fragment or in-page anchor (#edititem) is appended to the end of the URL but you are not placed on it. Instead you are placed at the top of the page and must scroll down to edit the particular item.

Note: This issue is present in master and 22.05.x, as far as I can tell.
Comment 2 Lucas Gass 2022-11-29 21:39:06 UTC
For me the empty searchid parameter doesn't seem to matter.

If I click 'Edit item', I am still at the top of the page ( fragment doesn't work )

but if I then go to the address bar and press return to refresh I am taken to the #edititem location. ( fragment does work )
Comment 3 Nick Clemens 2022-12-23 15:36:23 UTC
I believe it is the tabs:
koha-tmpl/intranet-tmpl/prog/js/staff-global.js
 51 $(document).ready(function() {
 52     $('#header_search').tabs({
 53         create: function( e, ui ){
 54             ui.panel.find("input:text:first").focus();
 55         },
 56         activate: function ( e, ui ) {
 57             ui.newPanel.find("input:text:first").focus();
 58         }
 59     });

They are moving the focus to the header search when the tabs are loaded - refreshing from the url doesn't fully reload the page, so the anchor works as we don't trigger the focus
Comment 4 Liz Rea 2022-12-23 15:55:53 UTC
Confirmed 22.05.07 and up
Comment 5 Lucas Gass 2023-01-10 18:07:22 UTC
(In reply to Nick Clemens from comment #3)
> I believe it is the tabs:
> koha-tmpl/intranet-tmpl/prog/js/staff-global.js
>  51 $(document).ready(function() {
>  52     $('#header_search').tabs({
>  53         create: function( e, ui ){
>  54             ui.panel.find("input:text:first").focus();
>  55         },
>  56         activate: function ( e, ui ) {
>  57             ui.newPanel.find("input:text:first").focus();
>  58         }
>  59     });
> 
> They are moving the focus to the header search when the tabs are loaded -
> refreshing from the url doesn't fully reload the page, so the anchor works
> as we don't trigger the focus

100% correct. I think we could check for the existence of a hash before we set the focus.
Comment 6 Lucas Gass 2023-01-10 18:12:27 UTC
Created attachment 145200 [details] [review]
Bug 32204: Check for hash before setting focus

1. Search the catalog and view a record detail page of a record with items
2. Click 'Edit items'
3. Choose one item from the list and click 'Edit'
4. The URL fragment or in-page anchor (#edititem) is appended to the end of the URL but you are not placed on it. Instead you are placed at the top of the page and must scroll down to edit the particular item.
5. Apply patch
6. Try steps 1 - 3 again, now you should be placed in the correct location (#edititem) when editing an item.
Comment 7 Lucas Gass 2023-01-10 18:53:46 UTC
This does interrupt workflows so I am setting the importance to normal.
Comment 8 David Nind 2023-01-10 19:48:04 UTC
Created attachment 145203 [details] [review]
Bug 32204: Check for hash before setting focus

1. Search the catalog and view a record detail page of a record with items
2. Click 'Edit items'
3. Choose one item from the list and click 'Edit'
4. The URL fragment or in-page anchor (#edititem) is appended to the end of the URL but you are not placed on it. Instead you are placed at the top of the page and must scroll down to edit the particular item.
5. Apply patch
6. Try steps 1 - 3 again, now you should be placed in the correct location (#edititem) when editing an item.

Signed-off-by: David Nind <david@davidnind.com>
Comment 9 Nick Clemens 2023-01-23 13:23:01 UTC
Created attachment 145572 [details] [review]
Bug 32204: Check for hash before setting focus

1. Search the catalog and view a record detail page of a record with items
2. Click 'Edit items'
3. Choose one item from the list and click 'Edit'
4. The URL fragment or in-page anchor (#edititem) is appended to the end of the URL but you are not placed on it. Instead you are placed at the top of the page and must scroll down to edit the particular item.
5. Apply patch
6. Try steps 1 - 3 again, now you should be placed in the correct location (#edititem) when editing an item.

Signed-off-by: David Nind <david@davidnind.com>
Signed-off-by: Nick Clemens <nick@bywatersolutions.com>
Comment 10 Tomás Cohen Arazi 2023-01-27 18:21:27 UTC
Pushed to master for 23.05.

Nice work everyone, thanks!
Comment 11 Matt Blenkinsop 2023-01-31 14:23:19 UTC
Nice work everyone!

Pushed to stable for 22.11.x
Comment 12 Lucas Gass 2023-02-01 16:25:32 UTC
This fix does not work with 22.05.x, no backport.