Skip to content

Commit

Permalink
fix: checkboxes and radios have mode default/on
Browse files Browse the repository at this point in the history
  • Loading branch information
MHajoha committed Nov 18, 2024
1 parent 4b4730f commit a721cde
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion classes/question_ui_renderer.php
Original file line number Diff line number Diff line change
Expand Up @@ -291,7 +291,14 @@ private function set_input_values_and_readonly(): void {
$lastvalue = $this->attempt->get_last_qt_var($name);
if (!is_null($lastvalue)) {
if ($type === 'checkbox' || $type === 'radio') {
if ($element->getAttribute('value') === $lastvalue) {
// FIXME: Unchecked checkboxes send nothing, so we have no way of distinguishing an explicitly
// unchecked checkbox from a checkbox which was not submitted (e.g. because it wasn't shown).
// As it stands, a default-checked but explicitly unchecked checkbox will be checked again on next
// view.
$shouldbechecked = $element->hasAttribute("value")
? $element->getAttribute('value') === $lastvalue
: $lastvalue === "on";
if ($shouldbechecked) {
$element->setAttribute('checked', 'checked');
} else {
$element->removeAttribute('checked');
Expand Down

0 comments on commit a721cde

Please sign in to comment.