diff --git a/mod/survey/survey.js b/mod/survey/survey.js
index 4f9947d6929..9f28c741db9 100644
--- a/mod/survey/survey.js
+++ b/mod/survey/survey.js
@@ -1,26 +1,27 @@
-function checkform(e) {
- var error = false;
- if (document.getElementById('surveyform')) {
- var surveyform = document.getElementById('surveyform');
- for (var i=0; i < surveycheck.questions.length; i++) {
- var tempquestion = surveycheck.questions[i];
- if (surveyform[tempquestion['question']][tempquestion['default']].checked) {
- error = true;
- }
- }
- }
- if (error) {
- alert(M.str.survey.questionsnotanswered);
- YAHOO.util.Event.preventDefault(e);
- return false;
- } else {
- return true;
- }
-}
-function survey_attach_onsubmit() {
+M.mod_survey = {};
+
+M.mod_survey.init = function(Y) {
if (document.getElementById('surveyform')) {
var surveyform = document.getElementById('surveyform');
- YAHOO.util.Event.addListener('surveyform', "submit", checkform);
+ Y.YUI2.util.Event.addListener('surveyform', "submit", function(e) {
+ var error = false;
+ if (document.getElementById('surveyform')) {
+ var surveyform = document.getElementById('surveyform');
+ for (var i=0; i < surveycheck.questions.length; i++) {
+ var tempquestion = surveycheck.questions[i];
+ if (surveyform[tempquestion['question']][tempquestion['default']].checked) {
+ error = true;
+ }
+ }
+ }
+ if (error) {
+ alert(M.str.survey.questionsnotanswered);
+ Y.YUI2.util.Event.preventDefault(e);
+ return false;
+ } else {
+ return true;
+ }
+ });
}
-}
\ No newline at end of file
+};
diff --git a/mod/survey/view.php b/mod/survey/view.php
index 4fce01a8eaf..8c450e073f4 100644
--- a/mod/survey/view.php
+++ b/mod/survey/view.php
@@ -198,10 +198,14 @@ $completion->set_module_viewed($cm);
$checkarray['questions'][] = Array('question'=>$question, 'default'=>$default);
}
}
- $PAGE->requires->js('/mod/survey/survey.js');
$PAGE->requires->data_for_js('surveycheck', $checkarray);
+ $module = array(
+ 'name' => 'mod_survey',
+ 'fullpath' => '/mod/survey/survey.js',
+ 'requires' => array('yui2-event'),
+ );
$PAGE->requires->string_for_js('questionsnotanswered', 'survey');
- $PAGE->requires->js_function_call('survey_attach_onsubmit');
+ $PAGE->requires->js_init_call('M.mod_survey.init', $checkarray, true, $module);
echo '
';
echo '';