Skip to content

Commit

Permalink
Merge pull request #1135 from drgrice1/radio-multi-answer-message-sty…
Browse files Browse the repository at this point in the history
…le-tweak

Center the RadioMultiAnswer error messages.
  • Loading branch information
Alex-Jordan authored Nov 29, 2024
2 parents 238144f + c974bda commit d52e7fa
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 16 deletions.
39 changes: 26 additions & 13 deletions macros/parsers/parserMultiAnswer.pl
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
# Artistic License for more details.
################################################################################

loadMacros("MathObjects.pl");
loadMacros('MathObjects.pl', 'PGbasicmacros.pl');

sub _parserMultiAnswer_init {
main::PG_restricted_eval('sub MultiAnswer {parser::MultiAnswer->new(@_)}');
Expand Down Expand Up @@ -175,7 +175,12 @@ sub single_check {
my $i = 0;
my $nonblank = 0;
if ($self->perform_check($ans)) {
push(@errors, '<TR><TD STYLE="text-align:left" COLSPAN="2">' . $self->{ans}[0]{ans_message} . '</TD></TR>');
push(
@errors,
main::tag(
'tr', main::tag('td', style => 'text-align:center', colspan => '2', $self->{ans}[0]{ans_message})
)
);
$self->{ans}[0]{ans_message} = "";
}
foreach my $result (@{ $self->{ans} }) {
Expand All @@ -185,26 +190,34 @@ sub single_check {
push(@text, check_string($result->{preview_text_string}, '__'));
push(@student, check_string($result->{student_ans}, '__'));
if ($result->{ans_message}) {
push(@errors,
'<TR VALIGN="TOP"><TD STYLE="text-align:right; border:0px" NOWRAP>'
. "<I>In answer $i</I>:&nbsp;</TD>"
. '<TD STYLE="text-align:left; border:0px">'
. $result->{ans_message}
. '</TD></TR>');
push(
@errors,
main::tag(
'tr',
main::tag(
'td',
style => 'text-align:right;white-space:nowrap;vertical-align:top',
main::tag('i', "In answer $i") . ':&nbsp;'
)
. main::tag('td', style => 'text-align:left', $result->{ans_message})
)
);
}
$score += $result->{score};
}
$ans->score($score / $self->length);
$ans->{ans_message} = $ans->{error_message} = "";
if (scalar(@errors)) {
$ans->{ans_message} = $ans->{error_message} =
'<TABLE BORDER="0" CELLSPACING="0" CELLPADDING="0" CLASS="ArrayLayout">'
. join('<TR><TD HEIGHT="4"></TD></TR>', @errors)
. '</TABLE>';
$ans->{ans_message} = $ans->{error_message} = main::tag(
'table',
class => 'ArrayLayout',
style => 'margin-left:auto;margin-right:auto;',
join(main::tag('tr', style => 'height: 4px', main::tag('td')), @errors)
);
}
if (@{ $self->{single_ans_messages} }) {
$ans->{ans_message} = $ans->{error_message} =
'<DIV>' . join('</DIV><DIV>', @{ $self->{single_ans_messages} }) . '</DIV>' . $ans->{ans_message};
join('', map { main::tag('div', $_) } @{ $self->{single_ans_messages} });
}
if ($nonblank) {
$ans->{preview_latex_string} =
Expand Down
6 changes: 3 additions & 3 deletions macros/parsers/parserRadioMultiAnswer.pl
Original file line number Diff line number Diff line change
Expand Up @@ -486,19 +486,19 @@ sub answer_evaluator {
main::tag(
'tr',
style => 'vertical-align:top',
main::tag('td', style => 'text-align:left', $result->{ans_message})
main::tag('td', style => 'text-align:center', $result->{ans_message})
)
);
}
}
for (@{ $self->{errorMessages} }) {
push(@errors, main::tag('tr', style => 'vertical-align:top', main::tag('td', style => 'text-align:left', $_)));
push(@errors, main::tag('tr', style => 'vertical-align:top', main::tag('td', $_)));
}
$ans->{ans_message} = $ans->{error_message} = '';
if (@errors) {
$ans->{ans_message} = $ans->{error_message} = main::tag(
'table',
style => 'border-collapse:collapse',
style => 'border-collapse:collapse; margin-left: auto; margin-right: auto;',
class => 'ArrayLayout',
join(main::tag('tr', main::tag('td', style => 'height:4px')), @errors)
);
Expand Down

0 comments on commit d52e7fa

Please sign in to comment.