MDL-68353 admin: Not use label tag in admin setting elements when needed
This commit is contained in:
@@ -49,15 +49,28 @@
|
||||
}}
|
||||
<div class="form-item row" id="{{id}}">
|
||||
<div class="form-label col-sm-3 text-sm-right">
|
||||
<label {{#labelfor}}for="{{labelfor}}"{{/labelfor}}>
|
||||
{{{title}}}
|
||||
{{#override}}
|
||||
<div class="alert alert-info">{{override}}</div>
|
||||
{{/override}}
|
||||
{{#warning}}
|
||||
<div class="alert alert-warning">{{warning}}</div>
|
||||
{{/warning}}
|
||||
</label>
|
||||
{{#customcontrol}}
|
||||
<p {{#labelfor}}id="{{labelfor}}_label"{{/labelfor}}>
|
||||
{{{title}}}
|
||||
{{#override}}
|
||||
<div class="alert alert-info">{{override}}</div>
|
||||
{{/override}}
|
||||
{{#warning}}
|
||||
<div class="alert alert-warning">{{warning}}</div>
|
||||
{{/warning}}
|
||||
</p>
|
||||
{{/customcontrol}}
|
||||
{{^customcontrol}}
|
||||
<label {{#labelfor}}for="{{labelfor}}"{{/labelfor}}>
|
||||
{{{title}}}
|
||||
{{#override}}
|
||||
<div class="alert alert-info">{{override}}</div>
|
||||
{{/override}}
|
||||
{{#warning}}
|
||||
<div class="alert alert-warning">{{warning}}</div>
|
||||
{{/warning}}
|
||||
</label>
|
||||
{{/customcontrol}}
|
||||
<span class="form-shortname d-block small text-muted">{{{name}}}</span>
|
||||
</div>
|
||||
<div class="form-setting col-sm-9">
|
||||
@@ -72,3 +85,16 @@
|
||||
{{#dependenton}}<div class="form-dependenton mb-4 text-muted">{{{.}}}</div>{{/dependenton}}
|
||||
</div>
|
||||
</div>
|
||||
{{#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}}
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -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}}
|
||||
|
||||
Reference in New Issue
Block a user