-
-
Notifications
You must be signed in to change notification settings - Fork 79
Add ansLabels option to parserMultiAnswer. #1489
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -48,6 +48,7 @@ sub new { | |
| singleResult => 0, | ||
| namedRules => 0, | ||
| cmpOpts => undef, | ||
| ansLabels => [], | ||
| checkTypes => 1, | ||
| allowBlankAnswers => 0, | ||
| tex_separator => $separator . '\,', | ||
|
|
@@ -416,33 +417,38 @@ sub NEW_NAME { | |
| main::RECORD_FORM_LABEL(shift); | ||
| } | ||
|
|
||
| sub generate_aria_label { | ||
| my ($self, $name, $part) = @_; | ||
| return main::generate_aria_label($self->{singleResult} ? $answerPrefix . $name . '_' . $part : $name, | ||
| $self->{ansLabels}[$part]); | ||
| } | ||
|
|
||
| # | ||
| # Produce an answer rule for the next item in the list, | ||
| # taking care to use names or extensions as needed | ||
| # by the settings of the MultiAnswer. | ||
| # | ||
| sub ans_rule { | ||
| my $self = shift; | ||
| my $size = shift || 20; | ||
| my $data = $self->{data}[ $self->{part} ]; | ||
| my $name = $self->ANS_NAME($self->{part}++); | ||
| if ($self->{singleResult} && $self->{part} == 1) { | ||
| my $label = main::generate_aria_label($answerPrefix . $name . "_0"); | ||
| main::RECORD_IMPLICIT_ANS_NAME($name) unless $self->{namedRules}; | ||
| return $data->named_ans_rule($name, $size, @_, aria_label => $label); | ||
| } | ||
| if ($self->{singleResult} && $self->{part} > 1) { | ||
| my $extension_ans_rule = $data->named_ans_rule_extension( | ||
| my $self = shift; | ||
| my $size = shift || 20; | ||
| my $part = $self->{part}; | ||
| my $data = $self->{data}[$part]; | ||
| my $name = $self->ANS_NAME($self->{part}++); | ||
| my $label = $self->generate_aria_label($name, $part); | ||
| if ($self->{singleResult}) { | ||
| if ($part == 0) { | ||
| main::RECORD_IMPLICIT_ANS_NAME($name) unless $self->{namedRules}; | ||
| return $data->named_ans_rule($name, $size, @_, aria_label => $label); | ||
| } | ||
| return $data->named_ans_rule_extension( | ||
| $name, $size, | ||
| answer_group_name => $self->{answerNames}{0}, | ||
| @_ | ||
| @_, | ||
| aria_label => $label | ||
| ); | ||
| # warn "extension rule created: $extension_ans_rule for ", ref($data); | ||
| return $extension_ans_rule; | ||
| } else { | ||
| main::RECORD_IMPLICIT_ANS_NAME($name) unless $self->{namedRules}; | ||
| return $data->named_ans_rule($name, $size, @_); | ||
| } | ||
| main::RECORD_IMPLICIT_ANS_NAME($name) unless $self->{namedRules}; | ||
| return $data->named_ans_rule($name, $size, @_, aria_label => $label); | ||
| } | ||
|
|
||
| # | ||
|
|
@@ -454,29 +460,30 @@ sub ans_array { | |
| my $self = shift; | ||
| my $size = shift || 5; | ||
| my $HTML; | ||
| my $data = $self->{data}[ $self->{part} ]; | ||
| my $name = $self->ANS_NAME($self->{part}++); | ||
| if ($self->{singleResult} && $self->{part} == 1) { | ||
| my $label = main::generate_aria_label($answerPrefix . $name . "_0"); | ||
| main::RECORD_IMPLICIT_ANS_NAME($name) unless $self->{namedRules}; | ||
| return $data->named_ans_array( | ||
| $name, $size, | ||
| answer_group_name => $self->{answerNames}{0}, | ||
| @_, aria_label => $label | ||
| ); | ||
| } | ||
| if ($self->{singleResult} && $self->{part} > 1) { | ||
| my $part = $self->{part}; | ||
| my $data = $self->{data}[$part]; | ||
| my $name = $self->ANS_NAME($self->{part}++); | ||
| my $label = $self->generate_aria_label($name, $part); | ||
| if ($self->{singleResult}) { | ||
| if ($part == 0) { | ||
| main::RECORD_IMPLICIT_ANS_NAME($name) unless $self->{namedRules}; | ||
| return $data->named_ans_array( | ||
| $name, $size, | ||
| answer_group_name => $self->{answerNames}{0}, | ||
| @_, aria_label => $label | ||
| ); | ||
| } | ||
| $HTML = $data->named_ans_array_extension( | ||
| $self->NEW_NAME($name), $size, | ||
| answer_group_name => $self->{answerNames}{0}, | ||
| @_ | ||
| @_, | ||
| aria_label => $label | ||
| ); | ||
| # warn "array extension rule created: $HTML for ", ref($data); | ||
| } else { | ||
| main::RECORD_IMPLICIT_ANS_NAME($name) unless $self->{namedRules}; | ||
| $HTML = $data->named_ans_array($name, $size, @_); | ||
| $HTML = $data->named_ans_array($name, $size, @_, aria_label => $label); | ||
| } | ||
| $self->{cmp}[ $self->{part} - 1 ] = $data->cmp(@ans_defaults); | ||
| $self->{cmp}[$part] = $data->cmp(@ans_defaults); | ||
| return $HTML; | ||
| } | ||
|
|
||
|
|
@@ -566,6 +573,14 @@ =head2 allowBlankAnswers | |
| Indicates whether to remove the blank-check prefilter from the answer checkers used for type checking | ||
| the student's answers. Default: 0. | ||
|
|
||
| =head2 ansLabels | ||
|
|
||
| An array reference of labels to be added to the assoicated answer box. By default answer boxes are | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
| labeled (C<aria-label>) with "answer X" or "answer X part Y" if C<singleResult> is used. These labels | ||
| are appeneded to the default label, e.g. "answer X part Y custom label", and can be used to improve | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
| the accessiblity. For example stating the side of the equation or part of an integral the answer | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
| box is used for. | ||
|
|
||
| =head2 format | ||
|
|
||
| An sprintf-style string used to format the students' answers for the results table when C<singleResult> | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Now that the initial value of
$self->{part}is being saved to a local variable, this should beSo the current value of
$self->{part}is saved to$partand then$self->{part}is incremented and not used again in the method.The same change should be made in the
ans_arraymethod.