diff --git a/admin/templates/setting.mustache b/admin/templates/setting.mustache index a3a3a227f26..498aa2c3c1c 100644 --- a/admin/templates/setting.mustache +++ b/admin/templates/setting.mustache @@ -49,15 +49,28 @@ }}
- + {{#customcontrol}} +

+ {{{title}}} + {{#override}} +

{{override}}
+ {{/override}} + {{#warning}} +
{{warning}}
+ {{/warning}} +

+ {{/customcontrol}} + {{^customcontrol}} + + {{/customcontrol}} {{{name}}}
@@ -72,3 +85,16 @@ {{#dependenton}}
{{{.}}}
{{/dependenton}}
+{{#customcontrol}} + {{#js}} + require(['jquery'], function($) { + $('#{{id}}_label').css('cursor', 'default'); + $('#{{id}}_label').click(function() { + $('#{{id}}') + .find('button, a, input:not([type="hidden"]), select, textarea, [tabindex]') + .filter(':not([disabled]):not([tabindex="0"]):not([tabindex="-1"])') + .first().focus(); + }); + }); + {{/js}} +{{/customcontrol}} diff --git a/lib/adminlib.php b/lib/adminlib.php index 1541db2f81a..fd87ec4b1db 100644 --- a/lib/adminlib.php +++ b/lib/adminlib.php @@ -1686,6 +1686,8 @@ abstract class admin_setting { private $forceltr = null; /** @var array list of other settings that may cause this setting to be hidden */ private $dependenton = []; + /** @var bool Whether this setting uses a custom form control */ + protected $customcontrol = false; /** * Constructor @@ -2081,6 +2083,16 @@ abstract class admin_setting { public function get_dependent_on() { return $this->dependenton; } + + /** + * Whether this setting uses a custom form control. + * This function is especially useful to decide if we should render a label element for this setting or not. + * + * @return bool + */ + public function has_custom_form_control(): bool { + return $this->customcontrol; + } } /** @@ -8925,6 +8937,7 @@ function format_admin_setting($setting, $title='', $form='', $description='', $l $context->description = highlight($query, markdown_to_html($description)); $context->element = $form; $context->forceltr = $setting->get_force_ltr(); + $context->customcontrol = $setting->has_custom_form_control(); return $OUTPUT->render_from_template('core_admin/setting', $context); } @@ -10384,6 +10397,7 @@ class admin_setting_configstoredfile extends admin_setting { $this->filearea = $filearea; $this->itemid = $itemid; $this->options = (array)$options; + $this->customcontrol = true; } /** diff --git a/lib/form/templates/element-group.mustache b/lib/form/templates/element-group.mustache index 4664a090292..e9a5c058149 100644 --- a/lib/form/templates/element-group.mustache +++ b/lib/form/templates/element-group.mustache @@ -22,7 +22,10 @@ require(['jquery'], function($) { $('#{{element.id}}_label').css('cursor', 'default'); $('#{{element.id}}_label').click(function() { - $('#{{element.id}}').find('button, a, input, select, textarea, [tabindex]:not([tabindex="-1"])').filter(':enabled').first().focus(); + $('#{{element.id}}') + .find('button, a, input:not([type="hidden"]), select, textarea, [tabindex]') + .filter(':not([disabled]):not([tabindex="0"]):not([tabindex="-1"])') + .first().focus(); }); }); {{/js}}