Skip to content

Commit 483fe3c

Browse files
committed
Fix the MultiAnswer macro when the namedRules option is used. The
problem is that the ANS_NAME method is called first when an answer rule is created (in the ans_rule method), and then again when answer evaluators are created (in the cmp method). Both times the NEW_ANS_NAME method is called and different answer names are recorded. This fix caches the answer names when they are first created in the ANS_NAME method, and then subsequent calls just return the recorded name.
1 parent 5e6c0a4 commit 483fe3c

File tree

1 file changed

+13
-14
lines changed

1 file changed

+13
-14
lines changed

macros/parserMultiAnswer.pl

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -411,22 +411,21 @@ sub setMessage {
411411
######################################################################
412412

413413
#
414-
# Produce the name for a named answer blank
415-
# (Use the standard name for the first one, and
416-
# create the prefixed names for the rest.)
414+
# Produce the name for a named answer blank.
415+
# (When the singleResult option is true, use the standard name for the first
416+
# one, and create the prefixed names for the rest.)
417417
#
418418
sub ANS_NAME {
419-
my $self = shift; my $i = shift; my $name;
419+
my $self = shift; my $i = shift;
420+
$self->{answerNames} = {} if !defined($self->{answerNames});
421+
return $self->{answerNames}->{$i} if defined($self->{answerNames}->{$i});
420422
if ($self->{singleResult}) {
421-
if (!$self->{id}) {
422-
$name = $self->{answerName} = main::NEW_ANS_NAME();
423-
$self->{id} = $answerPrefix.$name;
424-
}
425-
$name = $self->{id}."_".$i unless $i == 0;
423+
$self->{answerNames}->{0} = main::NEW_ANS_NAME() if (!$self->{answerNames}->{0});
424+
$self->{answerNames}->{$i} = $answerPrefix.$self->{answerNames}->{0}."_".$i unless $i == 0;
426425
} else {
427-
$name = main::NEW_ANS_NAME();
426+
$self->{answerNames}->{$i} = main::NEW_ANS_NAME();
428427
}
429-
return $name;
428+
return $self->{answerNames}->{$i};
430429
}
431430

432431
#
@@ -453,7 +452,7 @@ sub ans_rule {
453452
if ($self->{singleResult} && $self->{part} > 1) {
454453
my $extension_ans_rule =
455454
$data->named_ans_rule_extension(
456-
$name,$size, answer_group_name => $self->{answerName},
455+
$name,$size, answer_group_name => $self->{answerNames}->{0},
457456
@_);
458457
# warn "extension rule created: $extension_ans_rule for ", ref($data);
459458
return $extension_ans_rule;
@@ -474,12 +473,12 @@ sub ans_array {
474473
if ($self->{singleResult} && $self->{part} == 1) {
475474
my $label = main::generate_aria_label($answerPrefix.$name."_0");
476475
return $data->named_ans_array($name,$size,
477-
answer_group_name => $self->{answerName},
476+
answer_group_name => $self->{answerNames}->{0},
478477
@_,aria_label=>$label);
479478
}
480479
if ($self->{singleResult} && $self->{part} > 1) {
481480
$HTML = $data->named_ans_array_extension($self->NEW_NAME($name),$size,
482-
answer_group_name => $self->{answerName}, @_);
481+
answer_group_name => $self->{answerNames}->{0}, @_);
483482
# warn "array extension rule created: $HTML for ", ref($data);
484483
} else {
485484
$HTML = $data->named_ans_array($name,$size,@_);

0 commit comments

Comments
 (0)