MDL-55417 forms: Render form elements with a template

This change allows form elements to be overridden with a mustache template.
The template can even listen for form validation errors and supply the JS to
change the look of the form element when there is/isn't a validation error.

Initial support is for all core form elements including:

text, select, selectyesno and checkboxes, groups, dateselector, datetimeselector,
autocomplete, modvisible, advcheckbox, button, duration, filemanager, filepicker, editor, static, grading,
warning, textarea, password, url, submit, questioncategory, recaptcha.

Part of MDL-55071
This commit is contained in:
Damyon Wiese
2016-09-23 10:53:30 +01:00
committed by Dan Poltawski
parent ef18a21f93
commit 91bda4cd45
69 changed files with 1566 additions and 367 deletions
+7 -1
View File
@@ -28,6 +28,7 @@
global $CFG;
require_once("HTML/QuickForm/element.php");
require_once($CFG->dirroot.'/grade/grading/form/lib.php');
require_once($CFG->libdir.'/outputcomponents.php');
if (class_exists('HTML_QuickForm')) {
HTML_QuickForm::registerRule('gradingvalidated', 'callback', '_validate', 'MoodleQuickForm_grading');
@@ -47,7 +48,7 @@ if (class_exists('HTML_QuickForm')) {
* @copyright 2011 Marina Glancy
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class MoodleQuickForm_grading extends HTML_QuickForm_input{
class MoodleQuickForm_grading extends HTML_QuickForm_input implements templatable {
/** @var string html for help button, if empty then no help */
var $_helpbutton='';
@@ -63,6 +64,7 @@ class MoodleQuickForm_grading extends HTML_QuickForm_input{
*/
public function __construct($elementName=null, $elementLabel=null, $attributes=null) {
parent::__construct($elementName, $elementLabel, $attributes);
$this->_type = 'grading';
$this->gradingattributes = $attributes;
}
@@ -158,4 +160,8 @@ class MoodleQuickForm_grading extends HTML_QuickForm_input{
}
return true;
}
public function export_for_template(renderer_base $output) {
return $this->toHtml();
}
}