Skip to content

Commit 2031332

Browse files
authored
add option to hide "Number" tooltip (#277)
1 parent 0dbbf2b commit 2031332

File tree

4 files changed

+48
-3
lines changed

4 files changed

+48
-3
lines changed

lang/en/qtype_formulas.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -342,6 +342,8 @@
342342
$string['settings_heading_general_desc'] = '';
343343
$string['settings_heading_width'] = 'Default widths';
344344
$string['settings_heading_width_desc'] = 'Default width of input fields for the various answer types. For fields that are left empty, the settings from the plugin\'s style file will be used. Please use this settings carefully. Making the fields too small can make it difficult for your students to type their answer. Note that the exclamation mark icon shown for invalid answers takes up approximately 12 pixels.';
345+
$string['settingshownumbertooltip'] = 'Show "Number" tooltip';
346+
$string['settingshownumbertooltip_desc'] = 'Whether the tooltip indicating "Number" should be shown for that answer type. It might make sense to not show that tooltip, e. g. when working with children in elementary schools. This setting does not affect tooltips for other answer types or for combined fields.';
345347
$string['subqoptions'] = 'Unit settings';
346348
$string['subqtext'] = 'Part\'s text';
347349
$string['subqtext_help'] = 'Part text and placement of answer fields can be specified here. The placeholders that can be used to specify answer fields places are:

renderer.php

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -595,14 +595,24 @@ protected function create_input_box(qtype_formulas_part $part, $answerindex,
595595
'data-answertype' => ($answerindex === self::UNIT_FIELD ? 'unit' : $part->answertype),
596596
'data-withunit' => ($answerindex === self::COMBINED_FIELD ? '1' : '0'),
597597

598-
'data-toggle' => 'tooltip',
599-
'data-title' => $title,
600-
'data-custom-class' => 'qtype_formulas-tooltip',
601598
'title' => $title,
602599
'class' => "form-control formulas_{$titlestring} {$feedbackclass}",
603600
'maxlength' => 128,
604601
];
605602

603+
// If the answer type is "Number" and it is not a combined field, we only add the tooltip, if the
604+
// corresponding option is set.
605+
$iscombined = $inputattributes['data-withunit'] === '1';
606+
$isnumber = !$iscombined && $inputattributes['data-answertype'] === qtype_formulas::ANSWER_TYPE_NUMBER;
607+
$shownumbertooltip = get_config('qtype_formulas', 'shownumbertooltip');
608+
if (!$isnumber || $shownumbertooltip) {
609+
$inputattributes += [
610+
'data-toggle' => 'tooltip',
611+
'data-title' => $title,
612+
'data-custom-class' => 'qtype_formulas-tooltip',
613+
];
614+
}
615+
606616
if ($displayoptions->readonly) {
607617
$inputattributes['readonly'] = 'readonly';
608618
}

settings.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,14 @@
4040
0
4141
));
4242

43+
// Whether the tooltip for answer type "Number" should be shown.
44+
$settings->add(new admin_setting_configcheckbox(
45+
'qtype_formulas/shownumbertooltip',
46+
new lang_string('settingshownumbertooltip', 'qtype_formulas'),
47+
new lang_string('settingshownumbertooltip_desc', 'qtype_formulas'),
48+
1
49+
));
50+
4351
// Default delay for the on-the-fly validation's debounce timer.
4452
$settings->add(new admin_setting_configselect(
4553
'qtype_formulas/debouncedelay',

tests/behat/tooltips.feature

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,3 +95,28 @@ Feature: Display of tooltips
9595
And I press shift tab
9696
Then I should not see "Number"
9797
And "div.tooltip-inner" "css_element" should not exist
98+
99+
Scenario: Tooltip for Number is not shown if disabled
100+
When the following config values are set as admin:
101+
| shownumbertooltip | 0 | qtype_formulas |
102+
And I follow "Quiz 1"
103+
And I press "Attempt quiz"
104+
And I set the field "Answer" to "1"
105+
Then I should not see "Number"
106+
And "div.tooltip-inner" "css_element" should not exist
107+
108+
Scenario: Setting does not affect tooltip for combined field with answer type "Number"
109+
When the following config values are set as admin:
110+
| shownumbertooltip | 0 | qtype_formulas |
111+
And I follow "Quiz 3"
112+
And I press "Attempt quiz"
113+
And I set the field "Answer" to "5 m/s"
114+
Then I should see "Number and unit"
115+
116+
Scenario: Setting does not affect tooltip for other answer types
117+
When the following config values are set as admin:
118+
| shownumbertooltip | 0 | qtype_formulas |
119+
And I follow "Quiz 2"
120+
And I press "Attempt quiz"
121+
And I set the field "Answer" to "x"
122+
Then I should see "Algebraic formula"

0 commit comments

Comments
 (0)