Bug 8588 - Duplicate field IDs cause problems with SQL report parameter entry

Changes to markup and script to enable unique ids on form
fields. These changes allow for working label+input pairs
on one or more text and select inputs and multiple working
datepickers.

To test, create a report with more than one date parameter,
at least one text parameter, and one or more authorised
value parameters. The datepickers should each work properly,
and labels should by clickable.

Signed-off-by: Chris Cormack <chris@bigballofwax.co.nz>
Signed-off-by: Paul Poulain <paul.poulain@biblibre.com>
This commit is contained in:
Owen Leonard 2012-08-07 15:09:35 -04:00 committed by Paul Poulain
parent 6ca9b8f037
commit c9535a606a
2 changed files with 17 additions and 7 deletions

View file

@ -504,16 +504,22 @@ canned reports and writing custom SQL reports.</p>
<input type='hidden' name='reports' value="[% reports %]" />
<h1>Enter parameters for report [% name %]:</h1>
[% IF ( notes ) %]<p>[% notes %]</p>[% END %]
<fieldset class="rows">
<ol>
[% FOREACH sql_param IN sql_params %]
[% IF sql_param.input == 'date' %]
<p>
[% sql_param.entry %]: <input id="date_[% sql_param_entry %]" type="text" value="" size="10" name="sql_params" class="datepicker" />
</p>
<li>
<label for="date_[% sql_param_entry %][% loop.count %]">[% sql_param.entry %]:</label> <input id="date_[% sql_param_entry %][% loop.count %]" type="text" value="" size="10" name="sql_params" class="datepicker" />
</li>
[% ELSIF ( sql_param.input == 'text' ) %]
<li><label for="sql_params[% loop.count %]">[% sql_param.entry %]: </label><input id="sql_params[% loop.count %]" type="text" name="sql_params" /></li>
[% ELSE %]
<p>[% sql_param.entry %]: [% sql_param.input %]</p>
<li><label for="sql_params_[% sql_param.labelid %]">[% sql_param.entry %]:</label> [% sql_param.input %]</li>
[% END %]
[% END %]
<input type='submit' value='Run the report'/>
</ol>
</fieldset>
<fieldset class="action"><input type="submit" value="Run the report" /></fieldset>
</form>
[% END %]

View file

@ -508,6 +508,7 @@ elsif ($phase eq 'Run this report'){
for(my $i=0;$i<($#split/2);$i++) {
my ($text,$authorised_value) = split /\|/,$split[$i*2+1];
my $input;
my $labelid;
if ($authorised_value eq "date") {
$input = 'date';
}
@ -563,8 +564,11 @@ elsif ($phase eq 'Run this report'){
$authorised_lib{$value} = $lib;
}
}
$labelid = $text;
$labelid =~ s/\W//g;
$input =CGI::scrolling_list( # FIXME: factor out scrolling_list
-name => "sql_params",
-id => "sql_params_".$labelid,
-values => \@authorised_values,
# -default => $value,
-labels => \%authorised_lib,
@ -575,9 +579,9 @@ elsif ($phase eq 'Run this report'){
);
} else {
$input = "<input type='text' name='sql_params'/>";
$input = "text";
}
push @tmpl_parameters, {'entry' => $text, 'input' => $input };
push @tmpl_parameters, {'entry' => $text, 'input' => $input, 'labelid' => $labelid };
}
$template->param('sql' => $sql,
'name' => $name,