Bug 27124 - JS error "select2Width is not defined"
Summary: JS error "select2Width is not defined"
Status: CLOSED FIXED
Alias: None
Product: Koha
Classification: Unclassified
Component: Templates (show other bugs)
Version: Main
Hardware: All All
: P5 - low major
Assignee: Owen Leonard
QA Contact: Josef Moravec
URL:
Keywords:
Depends on: 22399
Blocks:
  Show dependency treegraph
 
Reported: 2020-12-01 09:33 UTC by Jonathan Druart
Modified: 2021-12-13 21:11 UTC (History)
8 users (show)

See Also:
Change sponsored?: ---
Patch complexity: Trivial patch
Documentation contact:
Documentation submission:
Text to go in the release notes:
Version(s) released in:
21.05.00,20.11.01
Circulation function:


Attachments
Bug 27124: JS error "select2Width is not defined" (1.59 KB, patch)
2020-12-03 16:16 UTC, Owen Leonard
Details | Diff | Splinter Review
Bug 27124: JS error "select2Width is not defined" (1.64 KB, patch)
2020-12-03 19:00 UTC, Lucas Gass (lukeg)
Details | Diff | Splinter Review
Bug 27124: JS error "select2Width is not defined" (1.71 KB, patch)
2020-12-07 16:46 UTC, Martin Renvoize (ashimema)
Details | Diff | Splinter Review
Bug 27124: JS error "select2Width is not defined" (2.60 KB, patch)
2020-12-10 11:54 UTC, Owen Leonard
Details | Diff | Splinter Review
Bug 27124: JS error "select2Width is not defined" (2.66 KB, patch)
2020-12-14 23:24 UTC, Lucas Gass (lukeg)
Details | Diff | Splinter Review
Bug 27124: JS error "select2Width is not defined" (2.71 KB, patch)
2020-12-16 15:00 UTC, Josef Moravec
Details | Diff | Splinter Review

Note You need to log in before you can comment on or make changes to this bug.
Description Jonathan Druart 2020-12-01 09:33:05 UTC
There is a JS error if select2.js is used outside of addbiblio.tt:
  ReferenceError: select2Width is not defined

Edit items view for instance.
Comment 1 Owen Leonard 2020-12-03 16:16:51 UTC Comment hidden (obsolete)
Comment 2 Lucas Gass (lukeg) 2020-12-03 19:00:51 UTC Comment hidden (obsolete)
Comment 3 Lucas Gass (lukeg) 2020-12-03 19:02:23 UTC
Seems to fix the console error in all the places!
Comment 4 Julian Maurice 2020-12-04 10:33:47 UTC
The use of global variable `select2Width' can be easily avoided here by replacing it by a call to $.fn.select2.defaults.set directly after [% INCLUDE 'select2.inc' %] in addbiblio.tt

Is there any benefit using this global variable ? (except for the shorter name)
Comment 5 Martin Renvoize (ashimema) 2020-12-07 16:46:56 UTC Comment hidden (obsolete)
Comment 6 Martin Renvoize (ashimema) 2020-12-07 16:47:25 UTC
Thanks for the quick fix, works as expected, no regressions found and passes a scripts.

Passing QA
Comment 7 Jonathan Druart 2020-12-09 08:57:37 UTC
There is a pending question at comment 4. Owen, can you answer please?
Comment 8 Owen Leonard 2020-12-09 14:17:01 UTC
(In reply to Jonathan Druart from comment #7)
> There is a pending question at comment 4. Owen, can you answer please?

If there is a better way to do it I'm happy for that solution to replace my patch.
Comment 9 Julian Maurice 2020-12-09 14:42:50 UTC
(In reply to Owen Leonard from comment #8)
> (In reply to Jonathan Druart from comment #7)
> > There is a pending question at comment 4. Owen, can you answer please?
> 
> If there is a better way to do it I'm happy for that solution to replace my
> patch.

Do you think that the suggested solution in comment 4 is a better solution ?
Comment 10 Owen Leonard 2020-12-10 11:54:37 UTC
Created attachment 114300 [details] [review]
Bug 27124: JS error "select2Width is not defined"

This patch changes the default width paramter passed to the
select2 plugin. This allows the basic MARC editor's Select2
widgets to be styled differently than on other pages.

To test, apply the patch and view various pages where the select2 plugin
is used:

 - Basic MARC editor
 - Items edit
 - Batch item edit
 - Authority editor

In each case check that the Select2 plugin works correctly to style
fields like collection code and home library.

On the basic MARC editor page these <select>s should have a width
that adjusts as the browser window changes. On other pages the width
should be fixed.

Check the browser console and confirm that there are no JavaScript
errors.

Update: Thanks to Julian for the suggested optimization
Comment 11 Owen Leonard 2020-12-10 11:55:55 UTC
(In reply to Julian Maurice from comment #9)
> Do you think that the suggested solution in comment 4 is a better solution ?

Yes. I was making an incorrect assumption about when the default had to be set.
Comment 12 Victor Grousset/tuxayo 2020-12-10 21:42:34 UTC
I tried even though I don't know well these places ^^"

>  - Basic MARC editor

Is it cataloguing/addbiblio.pl ? Because I don't have the JS error before applying the patch. And I don't field a field that look like a Select2.

>  - Authority editor

Which field?
Comment 13 Lucas Gass (lukeg) 2020-12-14 23:24:10 UTC
Created attachment 114400 [details] [review]
Bug 27124: JS error "select2Width is not defined"

This patch changes the default width paramter passed to the
select2 plugin. This allows the basic MARC editor's Select2
widgets to be styled differently than on other pages.

To test, apply the patch and view various pages where the select2 plugin
is used:

 - Basic MARC editor
 - Items edit
 - Batch item edit
 - Authority editor

In each case check that the Select2 plugin works correctly to style
fields like collection code and home library.

On the basic MARC editor page these <select>s should have a width
that adjusts as the browser window changes. On other pages the width
should be fixed.

Check the browser console and confirm that there are no JavaScript
errors.

Update: Thanks to Julian for the suggested optimization

Signed-off-by: Lucas Gass <lucas@bywatersolutions.com>
Comment 14 Josef Moravec 2020-12-16 14:59:48 UTC
(In reply to Victor Grousset/tuxayo from comment #12)
> I tried even though I don't know well these places ^^"
> 
> >  - Basic MARC editor
> 
> Is it cataloguing/addbiblio.pl ? Because I don't have the JS error before
> applying the patch. And I don't field a field that look like a Select2.

Yes it is addbiblio, on this page the error is not shown, it's the only one page using select2 which does not has this error

> >  - Authority editor
> 
> Which field?

I bet you should define some authorized value category to a field manually... I've done it that way, because it was easier to me than trying to find some defined by default (which maybe even don't exist)
Comment 15 Josef Moravec 2020-12-16 15:00:28 UTC
Created attachment 114441 [details] [review]
Bug 27124: JS error "select2Width is not defined"

This patch changes the default width paramter passed to the
select2 plugin. This allows the basic MARC editor's Select2
widgets to be styled differently than on other pages.

To test, apply the patch and view various pages where the select2 plugin
is used:

 - Basic MARC editor
 - Items edit
 - Batch item edit
 - Authority editor

In each case check that the Select2 plugin works correctly to style
fields like collection code and home library.

On the basic MARC editor page these <select>s should have a width
that adjusts as the browser window changes. On other pages the width
should be fixed.

Check the browser console and confirm that there are no JavaScript
errors.

Update: Thanks to Julian for the suggested optimization

Signed-off-by: Lucas Gass <lucas@bywatersolutions.com>

Signed-off-by: Josef Moravec <josef.moravec@gmail.com>
Comment 16 Josef Moravec 2020-12-16 15:02:11 UTC
QA script passed

Bug fixed, no regression found
Comment 17 Jonathan Druart 2020-12-21 09:20:23 UTC
Pushed to master for 21.05, thanks to everybody involved!
Comment 18 Fridolin Somers 2020-12-28 13:36:44 UTC
Pushed to 20.11.x for 20.11.01
Comment 19 Andrew Fuerste-Henry 2020-12-28 14:46:17 UTC
Missing dependencies, not backported to 20.05