Bug 25587 - JavaScript issue - "clear" button doesn't reset some dropdowns
Summary: JavaScript issue - "clear" button doesn't reset some dropdowns
Status: RESOLVED FIXED
Alias: None
Product: Koha
Classification: Unclassified
Component: Circulation (show other bugs)
Version: master
Hardware: All All
: P5 - low minor (vote)
Assignee: Peter Vashchuk
QA Contact: Testopia
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2020-05-22 15:08 UTC by Peter Vashchuk
Modified: 2020-11-30 21:52 UTC (History)
7 users (show)

See Also:
Change sponsored?: ---
Patch complexity: ---
Text to go in the release notes:
Version(s) released in:
20.11.00, 20.05.01, 19.11.07, 19.05.13


Attachments
Bug 25587: fix for "clear" button to reset all selects (1.63 KB, patch)
2020-05-22 15:18 UTC, Peter Vashchuk
Details | Diff | Splinter Review
Bug 25587: fix for "clear" button to reset all selects (2.26 KB, patch)
2020-05-22 16:33 UTC, Peter Vashchuk
Details | Diff | Splinter Review
Bug 25587: fix for "clear" button to reset all selects (2.31 KB, patch)
2020-05-22 21:44 UTC, Lucas Gass
Details | Diff | Splinter Review
Bug 25587: fix for "clear" button to reset all selects (2.41 KB, patch)
2020-06-05 07:35 UTC, Julian Maurice
Details | Diff | Splinter Review

Note You need to log in before you can comment on or make changes to this bug.
Description Peter Vashchuk 2020-05-22 15:08:18 UTC
On cgi-bin/koha/admin/smart-rules.pl “clear” button does not reset fields with a dropdown selector except the first one "Patron Category".
Comment 1 Peter Vashchuk 2020-05-22 15:18:56 UTC Comment hidden (obsolete)
Comment 2 Peter Vashchuk 2020-05-22 16:33:34 UTC
Created attachment 105272 [details] [review]
Bug 25587: fix for "clear" button to reset all selects

Button "clear" on cgi-bin/koha/admin/smart-rules.pl did not reset fields with a dropdown selector except the first one.

This happens because jQuery selector .find("select option:first")
in koha-tmpl/intranet-tmpl/prog/en/modules/admin/smart-rules.tt
selects only single first element in the whole group, as from jquery doc:
> The :first pseudo-class is equivalent to :eq( 0 ). It could also be written as :lt( 1 ). While this matches only a single element, :first-child can match more than one: One for each parent. (https://api.jquery.com/first-selector/)

And it works if replaced by: .find("select option:first-child")

To reproduce:
    1) Go to /cgi-bin/koha/admin/smart-rules.pl
    2) Start editing one of existing rules or filling a new one, change all selects to have non-first option selected. Fill text input fields with sample data.
    3) Reset all fields with the "clear" button.
    4) Observe that only the first dropdown field was reset to the first option while all others still contain previously given values, meanwhile all text input fields are cleared as expected.
    5) Apply the patch.
    6) Repeat steps 1, 2 and 3.
    7) Check that all dropdown fields were reset to first option, as expected.

Mentored-by: Andrew Nugged <nugged@gmail.com>
Comment 3 Lucas Gass 2020-05-22 21:44:39 UTC
Created attachment 105285 [details] [review]
Bug 25587: fix for "clear" button to reset all selects

Button "clear" on cgi-bin/koha/admin/smart-rules.pl did not reset fields with a dropdown selector except the first one.

This happens because jQuery selector .find("select option:first")
in koha-tmpl/intranet-tmpl/prog/en/modules/admin/smart-rules.tt
selects only single first element in the whole group, as from jquery doc:
> The :first pseudo-class is equivalent to :eq( 0 ). It could also be written as :lt( 1 ). While this matches only a single element, :first-child can match more than one: One for each parent. (https://api.jquery.com/first-selector/)

And it works if replaced by: .find("select option:first-child")

To reproduce:
    1) Go to /cgi-bin/koha/admin/smart-rules.pl
    2) Start editing one of existing rules or filling a new one, change all selects to have non-first option selected. Fill text input fields with sample data.
    3) Reset all fields with the "clear" button.
    4) Observe that only the first dropdown field was reset to the first option while all others still contain previously given values, meanwhile all text input fields are cleared as expected.
    5) Apply the patch.
    6) Repeat steps 1, 2 and 3.
    7) Check that all dropdown fields were reset to first option, as expected.

Mentored-by: Andrew Nugged <nugged@gmail.com>

Signed-off-by: Lucas Gass <lucas@bywatersolutions.com>
Comment 4 Julian Maurice 2020-06-05 07:35:30 UTC
Created attachment 105566 [details] [review]
Bug 25587: fix for "clear" button to reset all selects

Button "clear" on cgi-bin/koha/admin/smart-rules.pl did not reset fields
with a dropdown selector except the first one.

This happens because jQuery selector .find("select option:first")
in koha-tmpl/intranet-tmpl/prog/en/modules/admin/smart-rules.tt
selects only single first element in the whole group, as from jquery
doc:
> The :first pseudo-class is equivalent to :eq( 0 ). It could also be
> written as :lt( 1 ). While this matches only a single element,
> :first-child can match more than one: One for each parent.
> (https://api.jquery.com/first-selector/)

And it works if replaced by: .find("select option:first-child")

To reproduce:
    1) Go to /cgi-bin/koha/admin/smart-rules.pl
    2) Start editing one of existing rules or filling a new one, change
       all selects to have non-first option selected. Fill text input
       fields with sample data.
    3) Reset all fields with the "clear" button.
    4) Observe that only the first dropdown field was reset to the first
       option while all others still contain previously given values,
       meanwhile all text input fields are cleared as expected.
    5) Apply the patch.
    6) Repeat steps 1, 2 and 3.
    7) Check that all dropdown fields were reset to first option, as
       expected.

Mentored-by: Andrew Nugged <nugged@gmail.com>

Signed-off-by: Lucas Gass <lucas@bywatersolutions.com>
Signed-off-by: Julian Maurice <julian.maurice@biblibre.com>
Comment 5 Jonathan Druart 2020-06-15 10:00:26 UTC
Pushed to master for 20.11, thanks to everybody involved!
Comment 6 Aleisha Amohia 2020-06-22 03:57:30 UTC
backported to 20.05.x for 20.05.01 (by Lucas)
Comment 7 Aleisha Amohia 2020-06-22 04:02:00 UTC
backported to 19.11.x for 19.11.07
Comment 8 Victor Grousset/tuxayo 2020-07-03 05:16:03 UTC
Backported to 19.05.x branch for 19.05.13