Bug 37077: Fix report mutli-select for zero and single selections

This patch updates the javascript overriding the form submission when reports have multi select parameters.

When there are more than one multi selects, and the user selcts one value from each, it skips updating the value of the select, so it doens't send duplicate parameters anymore.

If there are no selections made it will pass '%' for all values. This allows the multi select to be optional in the report. If no selections are made it is assumed that you are not using that parameter to limit the report.

Test plan:
1. Go to Reports and create a report from SQL
   select *
   from items
   where
   homebranch in <<Libraries|branches:in>>
   and
   itype in <<Item type|itemtypes:in>>
3. Run the report but pick only 1 library and 1 item type
4. Click the "Show SQL code"
5. Notice that the two parameters were filled correctly
6. Run the report again with zero selections
7. Click the "Show SQL code"
8. Notice that the '%' is used for the parameter
9. Run the report again with combinations of single, multiple and zero selections
10. confirm the SQL code is generated as you would expect.

Signed-off-by: Pedro Amorim <pedro.amorim@ptfs-europe.com>

Signed-off-by: Marcel de Rooy <m.de.rooy@rijksmuseum.nl>
Signed-off-by: Katrin Fischer <katrin.fischer@bsz-bw.de>
(cherry picked from commit 6c6982b983)
Signed-off-by: Lucas Gass <lucas@bywatersolutions.com>
This commit is contained in:
Brendan Lawlor 2024-06-14 19:11:56 +00:00 committed by Lucas Gass
parent 13c6a4a1bb
commit b21efc1e4d
1 changed files with 8 additions and 3 deletions

View File

@ -882,7 +882,7 @@
<label for="sql_params_[% sql_param.labelid | html %]">[% sql_param.entry | html %]:</label>
[% IF (sql_param.select_multiple) %]
<select name="[%- sql_param.input.name | html -%]" tabindex="1" id="[%- sql_param.input.id | html -%]" multiple>
<option value="null" hidden></option>
<option value="%" hidden></option>
[% ELSE %]
<select name="[%- sql_param.input.name | html -%]" tabindex="1" id="[%- sql_param.input.id | html -%]">
[% END %]
@ -1585,8 +1585,13 @@
$('#report_param_form').on('submit', function(e) {
$('#report_param_form').find('select[multiple]').each( function (i) {
var $selected = $('option:first', this).val();
$(this).val($selected);
if( $(this).find('option:selected').length === 0 ) {
$(this).val(['%']);
}
else if( $(this).find('option:selected').length > 1 ) {
var $selected = $('option:first', this).val();
$(this).val($selected);
}
});
});
}