Skip to content
Browse files

Merge branch 'MDL-35395' of git://github.com/timhunt/moodle

  • Loading branch information...
2 parents 7447a1e + 6b65e50 commit 9f707d6c9b66ab4f1f2c8d9658352113a972e7e3 @stronk7 stronk7 committed Oct 9, 2012
Showing with 37 additions and 8 deletions.
  1. +37 −8 lib/formslib.php
View
45 lib/formslib.php
@@ -1263,6 +1263,9 @@ class MoodleQuickForm extends HTML_QuickForm_DHTMLRulesTableless {
/** @var bool Whether to display advanced elements (on page load) */
var $_showAdvanced = null;
+ /** @var bool whether to automatically initialise M.formchangechecker for this form. */
+ protected $_use_form_change_checker = true;
+
/**
* The form name is derived from the class name of the wrapper minus the trailing form
* It is a name with words joined by underscores whereas the id attribute is words joined by underscores.
@@ -1392,8 +1395,32 @@ function getShowAdvanced(){
return $this->_showAdvanced;
}
+ /**
+ * Call this method if you don't want the formchangechecker JavaScript to be
+ * automatically initialised for this form.
+ */
+ public function disable_form_change_checker() {
+ $this->_use_form_change_checker = false;
+ }
- /**
+ /**
+ * If you have called {@link disable_form_change_checker()} then you can use
+ * this method to re-enable it. It is enabled by default, so normally you don't
+ * need to call this.
+ */
+ public function enable_form_change_checker() {
+ $this->_use_form_change_checker = true;
+ }
+
+ /**
+ * @return bool whether this form should automatically initialise
+ * formchangechecker for itself.
+ */
+ public function is_form_change_checker_enabled() {
+ return $this->_use_form_change_checker;
+ }
+
+ /**
* Accepts a renderer
*
* @param HTML_QuickForm_Renderer $renderer An HTML_QuickForm_Renderer object
@@ -2243,13 +2270,15 @@ function startForm(&$form){
$this->_hiddenHtml .= $form->_pageparams;
}
- $PAGE->requires->yui_module('moodle-core-formchangechecker',
- 'M.core_formchangechecker.init',
- array(array(
- 'formid' => $form->getAttribute('id')
- ))
- );
- $PAGE->requires->string_for_js('changesmadereallygoaway', 'moodle');
+ if ($form->is_form_change_checker_enabled()) {
+ $PAGE->requires->yui_module('moodle-core-formchangechecker',
+ 'M.core_formchangechecker.init',
+ array(array(
+ 'formid' => $form->getAttribute('id')
+ ))
+ );
+ $PAGE->requires->string_for_js('changesmadereallygoaway', 'moodle');
+ }
}
/**

0 comments on commit 9f707d6

Please sign in to comment.
Something went wrong with that request. Please try again.