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
+19
View File
@@ -204,4 +204,23 @@ class MoodleQuickForm_autocomplete extends MoodleQuickForm_select {
}
return parent::onQuickFormEvent($event, $arg, $caller);
}
public function export_for_template(renderer_base $output) {
global $PAGE;
$this->_generateId();
$id = $this->getAttribute('id');
$PAGE->requires->js_call_amd('core/form-autocomplete', 'enhance', $params = array('#' . $id, $this->tags, $this->ajax,
$this->placeholder, $this->casesensitive, $this->showsuggestions, $this->noselectionstring));
$context = parent::export_for_template($output);
$context['tags'] = $this->tags;
$context['ajax'] = $this->ajax;
$context['placeholder'] = $this->placeholder;
$context['casesensitive'] = $this->casesensitive;
$context['showsuggestions'] = $this->showsuggestions;
$context['noselectionstring'] = $this->noselectionstring;
return $context;
}
}