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:
committed by
Dan Poltawski
parent
ef18a21f93
commit
91bda4cd45
+26
-3
@@ -26,6 +26,7 @@
|
||||
*/
|
||||
|
||||
require_once("HTML/QuickForm/text.php");
|
||||
require_once(__DIR__ . '/../outputcomponents.php');
|
||||
|
||||
/**
|
||||
* url type form element
|
||||
@@ -36,7 +37,7 @@ require_once("HTML/QuickForm/text.php");
|
||||
* @copyright 2009 Dongsheng Cai <[email protected]>
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
class MoodleQuickForm_url extends HTML_QuickForm_text{
|
||||
class MoodleQuickForm_url extends HTML_QuickForm_text implements templatable {
|
||||
/** @var string html for help button, if empty then no help */
|
||||
var $_helpbutton='';
|
||||
|
||||
@@ -61,7 +62,9 @@ class MoodleQuickForm_url extends HTML_QuickForm_text{
|
||||
if (!isset($this->_options['usefilepicker'])) {
|
||||
$this->_options['usefilepicker'] = true;
|
||||
}
|
||||
|
||||
parent::__construct($elementName, $elementLabel, $attributes);
|
||||
$this->_type = 'url';
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -89,7 +92,7 @@ class MoodleQuickForm_url extends HTML_QuickForm_text{
|
||||
* @return string
|
||||
*/
|
||||
function toHtml(){
|
||||
global $PAGE, $OUTPUT;
|
||||
|
||||
|
||||
$id = $this->_attributes['id'];
|
||||
$elname = $this->_attributes['name'];
|
||||
@@ -105,6 +108,16 @@ class MoodleQuickForm_url extends HTML_QuickForm_text{
|
||||
return $str;
|
||||
}
|
||||
|
||||
// print out file picker
|
||||
$str .= $this->getFilePickerHTML();
|
||||
|
||||
return $str;
|
||||
}
|
||||
|
||||
function getFilePickerHTML() {
|
||||
global $PAGE, $OUTPUT;
|
||||
|
||||
$str = '';
|
||||
$client_id = uniqid();
|
||||
|
||||
$args = new stdClass();
|
||||
@@ -119,7 +132,7 @@ class MoodleQuickForm_url extends HTML_QuickForm_text{
|
||||
if (count($options->repositories) > 0) {
|
||||
$straddlink = get_string('choosealink', 'repository');
|
||||
$str .= <<<EOD
|
||||
<button id="filepicker-button-js-{$client_id}" class="visibleifjs">
|
||||
<button id="filepicker-button-js-{$client_id}" class="visibleifjs btn btn-secondary">
|
||||
$straddlink
|
||||
</button>
|
||||
EOD;
|
||||
@@ -157,4 +170,14 @@ EOD;
|
||||
return 'default';
|
||||
}
|
||||
}
|
||||
|
||||
public function export_for_template(renderer_base $output) {
|
||||
$context = [];
|
||||
$context['frozen'] = $this->_flagFrozen;
|
||||
foreach ($this->getAttributes() as $name => $value) {
|
||||
$context[$name] = $value;
|
||||
}
|
||||
$context['filepickerhtml'] = $this->getFilePickerHTML();
|
||||
return $context;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user