From 455ff3fc7c057630998ead0a0152e98adbd36b24 Mon Sep 17 00:00:00 2001 From: Emmi Takkinen Date: Fri, 29 Dec 2023 13:48:39 +0200 Subject: [PATCH] Bug 34585: Fix behaviour of select dropdowns when editing circulation rules When chancing rule to edit via "Edit" button in circulation rules table, dropdown values aren't always changed correctly. Pressing "Edit" first time works, but after that previous rules values persist. Same happens when one tries to clear edit row, values aren't set to default values. This happens with every input with a dropdown in it. This mostly happanes because we set attribute "selected" to selected options, but never clear them which leads to values persisting. In columns "Patron category" and "Itemtype" value "All", or "*" as it is in code, doesn't match to any existing values from database and can't be changed via pressing "Edit" button. To reproduce: 1. Select a rule to edit and then select another rule to edit. 2. Repeat this couple of times and observe what values dropdowns fields display in edit row. => Selected values in dropdowns aren't always changed based on rule that you are currently editing. Instead after changing rule couple of times value doesn't change at all. 3. Press "Clear" button to return edit rows values back to default values. => Values in dropdowns aren't set back as default, instead they have same values as rule you edited before pressing "Clear". After reproducing problem, apply this patch and proceed to test "Clear" and "Edit" buttons. To test "Edit" button: 1. Again, select a rule to edit and then select a another rule to edit. 2. Observe what values dropdowns fields display in edit row. => Confirm that values are changed based on rule that you are currently editing and this behaviour doesn't change after selecting new rule to edit couple of times. To test "Clear" button: 1. Press "Clear" button. => Values in dropdowns should now be set as default values. Sponsored-by: Koha-Suomi Oy Signed-off-by: Lucas Gass --- .../intranet-tmpl/prog/en/modules/admin/smart-rules.tt | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/smart-rules.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/smart-rules.tt index cc4060dd90..4ca14cc91d 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/smart-rules.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/smart-rules.tt @@ -218,7 +218,7 @@ [% ELSE %] 0 [% END %] - + [% IF c == undef %] All [% ELSE %] @@ -230,7 +230,7 @@ [% ELSE %] 0 [% END %] - + [% IF i == undef %] All [% ELSE %] @@ -1460,6 +1460,7 @@ } }); $(edit_row).find("select").prop('disabled', false); + $(edit_row).find("select option:selected").removeAttr('selected'); $(edit_row).find("select option:first-child").attr("selected", "selected"); $(edit_row).find("td:last input[name='clear']").remove(); } @@ -1534,7 +1535,7 @@ $(current_column).find("select option").each(function(){ opt = $(this).attr('value'); if ( opt == itm_code ) { - $(this).attr('selected', 'selected'); + $(this).parent().val(opt); } }); var current_input_id = $(current_column).children('input').first().attr('id'); -- 2.30.2