From e4fbaf9f01a9ff9a80a7a872667c15807feabed8 Mon Sep 17 00:00:00 2001 From: "Hoang, Minh Duc" Date: Mon, 7 Apr 2025 14:23:57 +0200 Subject: [PATCH] #626 The name of the completion rule in the validation function should also be suffixed --- mod_form.php | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/mod_form.php b/mod_form.php index 26fcd227e..0db17b4c6 100644 --- a/mod_form.php +++ b/mod_form.php @@ -195,10 +195,12 @@ public function validation($data, $files) { } /** - * Add any completion rules for the form. - * @return string[] + * Returns the suffixed name for custom completion elements. + * + * @param string $fieldname + * @return string */ - public function add_completion_rules() { + protected function get_suffixed_name(string $fieldname): string { global $CFG; // Changes for Moodle 4.3 - MDL-78516. @@ -207,11 +209,18 @@ public function add_completion_rules() { } else { $suffix = $this->get_suffix(); } + return $fieldname . $suffix; + } + /** + * Add any completion rules for the form. + * @return string[] + */ + public function add_completion_rules() { $mform =& $this->_form; - $mform->addElement('checkbox', 'completionsubmit' . $suffix, '', + $mform->addElement('checkbox', $this->get_suffixed_name('completionsubmit'), '', get_string('completionsubmit', 'questionnaire')); - return ['completionsubmit' . $suffix]; + return [$this->get_suffixed_name('completionsubmit')]; } /** @@ -220,7 +229,7 @@ public function add_completion_rules() { * @return bool */ public function completion_rule_enabled($data) { - return !empty($data['completionsubmit']); + return !empty($data[$this->get_suffixed_name('completionsubmit')]); } }