Skip to content

Commit

Permalink
MDL-63015 mod_feedback: preview feedback questions in read-only.
Browse files Browse the repository at this point in the history
  • Loading branch information
paulholden committed Jul 29, 2024
1 parent 1a33da6 commit 088cb7a
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions mod/feedback/classes/complete_form.php
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 242,15 @@ public function is_frozen() {
return $this->mode == self::MODE_VIEW_RESPONSE;
}

/**
* Returns whether the form is considered read-only (e.g. when previewing it)
*
* @return bool
*/
private function is_readonly(): bool {
return $this->mode === self::MODE_PRINT;
}

/**
* Returns the current course module
* @return cm_info
Expand Down Expand Up @@ -327,6 336,11 @@ public function add_form_element($item, $element, $addrequiredrule = true, $setd
$element->freeze();
}

// For read-only forms, just disable each added element.
if ($this->is_readonly()) {
$this->_form->disabledIf($element->getName(), 'id');
}

// Add red asterisks on required fields.
if ($item->required) {
$required = $OUTPUT->pix_icon('req', get_string('requiredelement', 'form'), 'moodle', ['class' => 'ml-2']);
Expand Down

0 comments on commit 088cb7a

Please sign in to comment.